ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   put path in as variable (https://www.excelbanter.com/excel-programming/274358-put-path-variable.html)

Bruce Roberson

put path in as variable
 
I need this sub to allow me to specify the path to the
file I want to open here so that no matter what the
current path is, it will find this file. It works in cases
where this path is already the current path, but the open
file fails if another folder is the active path.
But this sub refuses to do what I want it to do. It just
keeps insisting an object is required on the line where I
set path = "D:\....

If I remove the " ", then it highlights the "/" and says
something about expects a line number. I wish this thing
would learn to speak English for a change.


Sub Import()
Dim cRows As Long
Dim path As String
Set path = "D:\myfiles\data\ttax\"
Sheets("Import").Select
Application.Goto Reference:=("Importarea")
Selection.CurrentRegion.Clear
Range("A1").Select
Workbooks.Open Filename:="path" & "LUSE.WK1"

Thanks,


Bruce

keepITcool

put path in as variable
 

Path is not an object it's a string
so you can't use SET

path="d:\data"

(officially it's LET path="d:\data" but contrary to SET VBA understands
if you leave it out so in practice nobody uses LET)



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Bruce Roberson" wrote:

I need this sub to allow me to specify the path to the
file I want to open here so that no matter what the
current path is, it will find this file. It works in cases
where this path is already the current path, but the open
file fails if another folder is the active path.
But this sub refuses to do what I want it to do. It just
keeps insisting an object is required on the line where I
set path = "D:\....

If I remove the " ", then it highlights the "/" and says
something about expects a line number. I wish this thing
would learn to speak English for a change.


Sub Import()
Dim cRows As Long
Dim path As String
Set path = "D:\myfiles\data\ttax\"
Sheets("Import").Select
Application.Goto Reference:=("Importarea")
Selection.CurrentRegion.Clear
Range("A1").Select
Workbooks.Open Filename:="path" & "LUSE.WK1"

Thanks,


Bruce



Dan E[_2_]

put path in as variable
 
Bruce,

Try removing the "Set" statement, no need for it with
a string object. path = "D:\myfiles\data\ttax\"
also path is a poor name as it is a member of several
classes, try myPath or something along those lines.

Dan E

"Bruce Roberson" wrote in message ...
I need this sub to allow me to specify the path to the
file I want to open here so that no matter what the
current path is, it will find this file. It works in cases
where this path is already the current path, but the open
file fails if another folder is the active path.
But this sub refuses to do what I want it to do. It just
keeps insisting an object is required on the line where I
set path = "D:\....

If I remove the " ", then it highlights the "/" and says
something about expects a line number. I wish this thing
would learn to speak English for a change.


Sub Import()
Dim cRows As Long
Dim path As String
Set path = "D:\myfiles\data\ttax\"
Sheets("Import").Select
Application.Goto Reference:=("Importarea")
Selection.CurrentRegion.Clear
Range("A1").Select
Workbooks.Open Filename:="path" & "LUSE.WK1"

Thanks,


Bruce




steve

put path in as variable
 
Also remove the quotes around "path" - just use := path &

steve

"Dan E" wrote in message
...
Bruce,

Try removing the "Set" statement, no need for it with
a string object. path = "D:\myfiles\data\ttax\"
also path is a poor name as it is a member of several
classes, try myPath or something along those lines.

Dan E

"Bruce Roberson" wrote in message

...
I need this sub to allow me to specify the path to the
file I want to open here so that no matter what the
current path is, it will find this file. It works in cases
where this path is already the current path, but the open
file fails if another folder is the active path.
But this sub refuses to do what I want it to do. It just
keeps insisting an object is required on the line where I
set path = "D:\....

If I remove the " ", then it highlights the "/" and says
something about expects a line number. I wish this thing
would learn to speak English for a change.


Sub Import()
Dim cRows As Long
Dim path As String
Set path = "D:\myfiles\data\ttax\"
Sheets("Import").Select
Application.Goto Reference:=("Importarea")
Selection.CurrentRegion.Clear
Range("A1").Select
Workbooks.Open Filename:="path" & "LUSE.WK1"

Thanks,


Bruce







All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com