Doc in new location.

imback2nite

Board Regular
Joined
Oct 30, 2004
Messages
211
Office Version
  1. 2003 or older
Platform
  1. Windows
Hopefully this is an easy one. I have a command button that I want to be able to find a Word document. Now this document will always be in the same place and I’ve been using this code to get to it.

Private Sub CommandButton1_Click()
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
On Error Resume Next
Set wrdDoc = wrdApp.Documents.Open("D:\Documents and Settings\Ken\My Documents\Computer Stuff\dumb_users.doc")
On Error GoTo 0
Set wrdDoc = wrdApp.Documents.Open("E:\Documents and Settings\Ken\My Documents\Computer Stuff\dumb_users.doc")
On Error GoTo 0
End Sub

Here’s the problem. I have this on a Flash Drive and sometimes the Flash is allocated the drive of E: or even F: . Is there a way for the code include looking in Drives all the way to drive G:? I was using a Hyperlink to access the Word document but was having the same problem. Also, is there a way for the code and give an error message reading, “Please Contact” if the file is still not found without giving a Excel error message?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
the Dir() function could help here i think..

Code:
if Dir ("D:\Documents and Settings\Ken\My Documents\Computer Stuff\dumb_users.doc")
<>"" then open my document
elseif Dir ("E:\Documents and Settings\Ken\My Documents\Computer Stuff\dumb_users.doc")
<>"" then open my document
Dir ("F:\Documents and Settings\Ken\My Documents\Computer Stuff\dumb_users.doc")
<>"" then open my document
 
Upvote 0
I think I'm missing something. 'then open my document' will open the document if the file is found? I'm getting an error message.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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