Solved

putting quotes around a string in VB Script  -  Windows 7

Posted on 2014-03-04
3
302 Views
Last Modified: 2014-03-04
Experts,

I have a string that has the address of a directory.  I just built this string and now I want to see if it exists.  How do I add quotation marks around the directory?

Currently string  myDir has the value below in it.



myDir= \\Main\FolderA\FolderB\FolderC\FolderD

I need  "\\Main\FolderA\FolderB\FolderC\FolderD"  to test the presence of the folder
0
Comment
Question by:morinia
3 Comments
 
LVL 8

Expert Comment

by:5teveo
ID: 39904467
Try

myDir= '"\\Main\FolderA\FolderB\FolderC\FolderD"' <--singles quotes on outside of string

myDir= ""\\Main\FolderA\FolderB\FolderC\FolderD"" <--2 double quotes on outside of string

myDir= """\\Main\FolderA\FolderB\FolderC\FolderD""" <--3 double quotes on outside of string
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 300 total points
ID: 39904530
I use a small function for this, as shown below:

myDir = Quote("\\Main\FolderA\FolderB\FolderC\FolderD")

' Small routine to add double quotes around a string
Function Quote(strText)
   Quote = Chr(34) & strText & Chr(34)
End Function

Open in new window

~bp
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39904563
You don't need quotation marks if myDir is a string variable, just pass myDir to your function that tests the path.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 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