Opening New File Word and Excel from VBA

weaselmcguff

Board Regular
Joined
Feb 24, 2006
Messages
246
I have a userform that searches for a particular file. At the moment it is pulling up Excel and Word Files from a predefined directory.

I am trying to figure out how to load the file that they select. selecting the file I have figured out. This is the code I am trying to use for Word atm.

Private Sub shipopen_Click()
Dim newApp As Object
Set newApp = CreateObject("word.application")
newApp.Application.Visible = True
newApp.Documents.Open Filename:=ship3
End Sub

the ship3 is the actual full location of the file where it is listed at
ie. c:\mydocuments\user2\document1.doc

i am getting a Run Time Error 13. Type Mismatch.

Any help? or suggestion.

Also need to do the same for an excel file.

Thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You have to give the file name in quotes otherwise it may give a mismatch error. Watch for the space in the file name. Something like this

Code:
Private Sub shipopen_click()
    Dim newApp As Object
    Set newApp = CreateObject("word.application")
    newApp.Application.Visible = True
    newApp.Documents.Open Filename:="C:\Excel Help.doc"
End Sub
 
Upvote 0
Is there a way to utilize the variable as the filename?

since it is stored as ship3

or do i need to covert ship3 to c:\mydocuments\user2\shipping.doc

Thanks
 
Upvote 0
How is the variable ship3 declared and how is the document's path and name assigned to it? This is not included in your code snippet.

eg
Code:
Dim Ship3 As String
 
Ship3 = "c:\mydocuments\user2\shipping.doc"
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top