I would very much appreciate if someone could help me.
On my database I have placed a button on the Main Menu for users to access a manual on how to use the database. Essentially, I want to open a Word document and bring it into focus ON TOP of the database. In addition, as I regularly transfer (copy) the database onto the C drive of my laptop whenever I need to use it in the field, the code specifies that if there is an error in trying to open the Word document from one drive, it should open it from another.
I know nothing about VBA but managed to put together something that mostly works really well (thank you Internet!!!!). On the laptop it works perfectly: it opens Word, transfers focus to it, and opens the document from the correct pathway. However, on my desktop, where the hyperlink is to a document on the office server, it works fine except that it does NOT bring Word to the fore, just flashes on the taskbar at the bottom.
The odd thing is, that if I open the VBA window and close it again (without making any changes), it works just fine, activating the Word document in the foreground.
Below is the code I am using. Is anyone able to spot why it does this?
Private Sub DataManualcmd_Click()
Dim LWordDoc As String
Dim LTopWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "P:\Marketing\Sales & Stocks\Transhipment Templates\Manual - Transhipment and Data Analysis.docx"
LTopWordDoc = "C:\Documents and Settings\CFL\My Documents\Sales programmes & manuals\Manual - Transhipment and Data Analysis.docx"
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
oApp.Activate
'Open the Document
On Error Resume Next
oApp.Documents.Open FileName:=LTopWordDoc
If Error <> 0 Then
oApp.Documents.Open FileName:=LWordDoc
End If
End Sub
Just a note which I am sure you will be aware of: without the oApp.Activate, Word doesn't come to the fore at all
Thank you for your time.