Path and File Name

R

Ronbo

I am trying to create the following path and file name;

C:\Documents and Settings\My Documents\John Jul 04
Info\DATA INPUT." _

Cell B1 = Johnson & Paul


I am using:

Dim sName As String, sDate As String

sName = (Left(Range("B1"), 4))
sDate = "" & Format(DateSerial(Year(Date), Month
(Date) - 1, 1), "mmm yy")


With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\My
Documents\sName & sDate & EOM INFO\DATA INPUT." _

But it can not find the file. What is wrong with the
code?

Thanks for any help
 
E

Ed

Couple of thoughts - don't know if any will apply -
-- Isn't "C:\Documents and Settings\My Documents" usually
"C:\Documents and Settings\USERNAME\My Documents"?
-- Your sample file folder name "John Jul 04 Info" has spaces in it.
Does "sName & sDate & EOM INFO" create those spaces"
-- Your sample file folder name "John Jul 04 Info" has "Info". Your
code "sName & sDate & EOM INFO" has "EOM INFO".

You might try creating your file path and name as a String and show it
in a message box to verify it during code creation before using the string
in With ActiveSheet.QueryTables.Add(Connection:= "TEXT; sFile")

HTH
Ed
 
G

Guest

-----Original Message-----
Couple of thoughts - don't know if any will apply -
-- Isn't "C:\Documents and Settings\My Documents" usually
"C:\Documents and Settings\USERNAME\My Documents"?
-- Your sample file folder name "John Jul 04 Info" has spaces in it.
Does "sName & sDate & EOM INFO" create those spaces"
-- Your sample file folder name "John Jul 04 Info" has "Info". Your
code "sName & sDate & EOM INFO" has "EOM INFO".

You might try creating your file path and name as a String and show it
in a message box to verify it during code creation before using the string
in With ActiveSheet.QueryTables.Add(Connection:= "TEXT; sFile")

HTH
Ed




.
1. the EOM INFO is the same
2. USERNAME is the same
2. you are correct i need to see what the code is
producing and I have tried MsgBox but I get -
C:\Documents and Settings\UserName\My Documents\sName &
sDate & EOM INFO\DATA INPUT...

How do you get the string in a MsgBox rather than the
alpha sName?
 
E

Ed

2. you are correct i need to see what the code is
producing and I have tried MsgBox but I get -
C:\Documents and Settings\UserName\My Documents\sName &
sDate & EOM INFO\DATA INPUT...

How do you get the string in a MsgBox rather than the
alpha sName?

Your posted code is:
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\My
Documents\sName & sDate & EOM INFO\DATA INPUT." _

I would do:
Dim strFile As String
strFile = "C:\Documents and Settings\My Documents\" & _
sName & sDate & _
"EOM INFO\DATA INPUT." <<(is that period a typo?)
(in the real code, do you have a .txt or .doc?)

MsgBox strFile

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" strFile, Destination:= etc. . . .

Step through using F8; if the message box comes up incorrect, stop
the code and fix the string.

HTH
Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

MsgBox & String 3
MsgBox String 2 4
Import Data 1
MsgBox & String 3 2
VLOOKUP not working in VBA 2
run time error 53 10
Importing Multiple Text File in Excel 4
Senders email address in saved attachment 1

Top