Solved

Word VBA File Names

Posted on 2013-01-07
5
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

626 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