Code to Open A Word Document in VBA

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.
LVL 1
FaheemAhmadGulAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
Hello FaheemAhmadGul,

Application.Documents.Open ("C:\Reports\Jaunary\" & FirstPart & "\" & SecondPart)

Regards,
Chris
0
Chris BottomleySoftware Quality Lead EngineerCommented:
FaheemAhmadGul,

Sorry I initially thought folder and filename ... perhaps:

Application.Documents.Open ("C:\Reports\Jaunary\" & FirstPart & SecondPart)


chris_bottomley
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrahamSkanRetiredCommented:
I think that you might be omitting the space:

MyDoc = Application.Documents.Open ("C:\Reports\Jaunary\" & FirstPart & " " & SecondPart)

I also notice that there is an 's' missing, but that might just be a typing error for this question.
0
FaheemAhmadGulAuthor Commented:
Many thanks. It worked perfectly. I am very grateful.
0
FaheemAhmadGulAuthor Commented:
Thanks Graham for your comment. I also noticed the missing space (" " ) and I corrected it myself.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.