BenGee

Board Regular
Joined
Mar 5, 2016
Messages
168
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.
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,520
Office Version
  1. 365
Platform
  1. Windows
A word file is not a workbook, hence you cannot open it like one.
What are you trying to do?
 

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
168
Oh that's embarrassing and fairly obvious.

Essentially, I'm just trying to open a word document in a specified network location
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,520
Office Version
  1. 365
Platform
  1. Windows
Can you post your complete code?
 

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
168

ADVERTISEMENT

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.
 

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
168
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:

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
168
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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,306
Messages
5,527,921
Members
409,793
Latest member
mavrik_stet

This Week's Hot Topics

Top