Solved

Word VBA File Names

Posted on 2013-01-07
5
409 Views
Last Modified: 2013-01-07
I had a document that was created in Word 2003 (vba 6.5)/Windows XP.  One of the operations of this document was to open another document that the user selects when clicking on a command button.  This was done through the following code.

Documents.Open fileName:=matrixdoc, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, Visible:=False

Open in new window


We have now moved to a new environment; Word 2010 (VBA 7)/Windows 7.  

Since this we have had problems with this code.  If the files have been stored on a local drive, when the user selects a file “ “ is added to the file name e.g “”c:\file.docx””.  If the file is stored on a network drive, this isn’t the case, so the selected file will be “c:\file.docx”.  

Does anyone know why this is happening and whether there is a quick fix rather than having to do an IF statement to see if “” has been added to the file name and deleting if it has?  

It is causing a problem because these files can be stored either on a local or network drive so I need a system that works in both scenarios.
0
Comment
Question by:jdc1944
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38750547
If you are saying that the value of the variable matrixdoc is incorrect, we will need to see the code that produces it.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 38750561
How is matrixdoc  defined? ... essentially ensure it is defined as a string and then this shouldn't happen ... not that I understand how it is happening but I have no such issues when using a string type variable.

Chris
0
 
LVL 2

Author Comment

by:jdc1944
ID: 38750728
Sorry, the code that produces the variable is as follows:

Dim dlg As Dialog
Dim matrixdoc As String
Set dlg = Dialogs(wdDialogFileOpen)
   If dlg.Display = -1 Then
        matrixdoc = dlg.Name
   End If

Open in new window

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 38750866
I'm not in a position to test it at the moment, but you could always try using Replace:

matrixdoc = Replace(dlg.Name, """","")
0
 
LVL 2

Author Closing Comment

by:jdc1944
ID: 38751052
This seems to have sorted it, thanks.  

I'm fairly new to VB and wasn't aware of replace.  I'm sure it will come in handy in the future.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now