I'm trying to import a daily filename_YYYYMMDD from a directory, but cannot get the VBA codes to import the file as a text file into Excel -


sub macro1()      dim fs, f object      dim strpath string     strpath = "filename_" + format(date, "yyyymmdd")     set fs = createobject("scripting.filesystemobject")     set f = fs.opentextfile(strpath, 1, 0)      activesheet.querytables.add(connection:= _     "text;strpath", destination:= _     range("a1"))  end sub 

'-----i'm not sure i'm missing above in vba, obviously, works when point filename manually in macro set-up-----------------------------

sub macro1()      activesheet.querytables.add(connection:= _     "text;c:\desktop\filename_20140101.txt", destination:= _     range("a1"))  end sub 

' thanks!!!!

it looks though aren't passing strpath connection , missing file extension (.txt), need as:

with activesheet.querytables.add(connection:= _     "text;" & strpath, destination:= _     range("a1")) 

with strpath set full path including extension:

strpath = "c:\desktop\filename_" + format(date, "yyyymmdd") & ".txt" 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -