Saving Workbook with Variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been trying to figure out how to save or open a workbook using a
variable. I keep getting the error "Type-declaration character doesn't match
declared data type". Here is an example of what i am trying to do:

Dim y as string
y = Range("A1")
ChDir "G:the current directory\" & z&
Workbooks.OpenText Filename:= _
"G:the current directory\" & z & "\" & y&
 
I think you might need double quote marks at the end of the line. One thing I
do is even set the Directory to a variable and use like:

MyDir = "\\YadaYada\SomeFolder\"
MyWrkbName = "My File.xls"

Workbooks.Open Filename:=MyDir & MyWrkbName & ""
 
Try this

Dim y As String
y = Range("A1")
ChDir "d:the current directory\" & z & ""
Workbooks.OpenText Filename:= _
"G:the current directory\" & z & "\" & y & ""
 

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

Back
Top