Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to get Cell value and use as file name in macro
I am trying to open a file which has a path name based on use requirement. I am including that path name to a cell in my worksheet. I want m macro to take that cell content everytime I run the macro and ope another file based on that path. First I import file 1. i.e. file 1 = will have some thing like this c:\keyur\keyur.txt which I am putting in cell A1 now I want macro to read the content of A1 and use as filepath name an import keyur.txt in worksheet. I tried following but did not work. So everytime pathname changes in file 2 it will import different file. Range("B6").Select FileNm = Sheets("Sheet1").Range("A1").Value With ActiveSheet.QueryTables.Add(Connection:="TEXT;File Nm", _ Destination:=Range("B6")) .Name = "rpt_chg_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 437 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = True .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With ActiveWindow.SmallScroll Down:=-3 End Su -- halarikeyu ----------------------------------------------------------------------- halarikeyur's Profile: http://www.excelforum.com/member.php...fo&userid=1575 View this thread: http://www.excelforum.com/showthread.php?threadid=27266 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to get Cell value and use as file name in macro
halarikeyur This line of code will not work as you have enclosed your variabl inside halarikey quote marks which makes it text With ActiveSheet.QueryTables.Add(Connection:="TEXT;File Nm", _ try With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & FileNm, -- mudrake ----------------------------------------------------------------------- mudraker's Profile: http://www.excelforum.com/member.php...nfo&userid=247 View this thread: http://www.excelforum.com/showthread.php?threadid=27266 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how to copy a cell in excell and paste in a txt file with macro | Excel Discussion (Misc queries) | |||
excel - create a macro to use cell text as part of a file name | New Users to Excel | |||
How to save file in a macro taking new name from cell contents? | Excel Discussion (Misc queries) | |||
macro save a file name from a cell in 1st worksheet | Excel Discussion (Misc queries) | |||
This one is tricky....Macro to save file as cell value x in di | Excel Discussion (Misc queries) |