Code to Open A Word Document in VBA
Posted on 2009-05-23
I would like to be able to open a word file through the click event of a button on a VBA project form.
The following line of code does that for me. It opens a document Blood Results New for me.
Application.Documents.Open ("C:\Reports\Jaunary\Blood Results New.doc")
However due to some special reasons I wish to provide the name of the file to be opened through a through two string variables rather than directly.
For example my preferred code would be like this.
Dim FirstPart as String
Dim SecondPart as String
FirstPart = Blood Result
SecondPart = New.Doc
Then I would like to open the file Blood Result New.doc through code similar to the following.
Application.Documents.Open ("C:\Reports\Jaunary\ FirstPart & SecondPart")
I had hoped that this new line of code will do the same job for me as the code I have listed before, but unfortunately it does not work.
Many thanks for your help.