VBA Help with Workbooks.Open not working..

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
196
Hi

I have this code to open up a file which works when it's an excel doc;
Code:
    Workbooks.Open Filename:="[URL="file://\\servertest\Test Administration\Dep"]\\servertest\Test Administration\Dep[/URL]artment Name\Dashboards\Test 1\Book1.xlsx"

But doesn't work when it's a word doc (run-time error 1004) with this code;
Code:
    Workbooks.Open Filename:="[URL="file://\\servertest\Test Administration\Department Name"]\\servertest\Test Administration\Department Name[/URL]\Dashboards\Test 1\Test.docx"

I'm unsure why? Any help would be appreciated.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
A word file is not a workbook, hence you cannot open it like one.
What are you trying to do?
 
Upvote 0
Oh that's embarrassing and fairly obvious.

Essentially, I'm just trying to open a word document in a specified network location
 
Upvote 0
Can you post your complete code?
 
Upvote 0
At the moment, it's literally just;
Code:
Sub CoverPage_Button4_2_Click()
    Workbooks.Open Filename:="\\servertest\Test Administration\Department Name\Dashboards\Test 1\Test.docx"
End Sub

Since it worked for a workbook, I thought it would be something similar for a word doc.
 
Upvote 0
Perfect, thank you. Got it all working now.

Complete code is;

Code:
Sub CoverPage_Button4_3_Click()
    Dim Name As String
    Name = Environ("username")
    Set wordapp = CreateObject("word.Application")
    
    wordapp.documents.Open "[URL="file://\\servertest\Test"]\\servertest\Test[/URL] Administration\Department Name\Dashboards\Test Environment\Test Doc" & Name & ".docx"
    wordapp.Visible = True
    wordapp.Activate
End Sub
 
Last edited:
Upvote 0
Adapted version for password word being password protected;

Code:
Sub CoverPage_Button4_3_Click()
    
    Dim Name As String
    Dim Password As String
    Dim Path
    Dim Form
    
    Name = Environ("username")
    Password = "Password"
    Path = "[URL="file://\\servertest\Test"]\\servertest\Test[/URL] Administration\Department Name\Dashboards\Test Environment\Test Doc" & Name & ".docx"
        
    Set wordapp = CreateObject("word.Application")

    
    Form = wordapp.Documents.Open(Path, PasswordDocument:=Password)
    wordapp.Visible = True
    wordapp.Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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