Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import Data macro


I'm trying to automate the Import Data process somewhat; hence I
recorded the "IMPORT_DATA" macro below. I need a macro that does
everything in IMPORT_DATA *except* use the predetermined file path and
file name. That is, I want to be prompted to browse for or insert the
path and file name. Then, proceed with the rest of the IMPORT_DATA, as
seen below. How can this be done?

Thx for any info you can provide.
-KH

Sub IMPORT_DATA()

Cells.Select
With ActiveSheet.QueryTables.Add(Connection:= _

"TEXT;\\Dell_Inspirion5100\G\household-appliances_com\eCost\10273764-eCOST_com_eZ_Affiliate_Program.txt"
_
, Destination:=Range("A1"))
..Name = "10273764-eCOST_com_eZ_Affiliate_Program"
..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 = xlTextQualifierNone
..TextFileConsecutiveDelimiter = False
..TextFileTabDelimiter = False
..TextFileSemicolonDelimiter = False
..TextFileCommaDelimiter = False
..TextFileSpaceDelimiter = False
..TextFileOtherDelimiter = "|"
..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, 1, 1, 1, 1, 1, 1, 1, 1)
..TextFileTrailingMinusNumbers = True
..Refresh BackgroundQuery:=False
End With
ActiveWorkbook.Save

End Sub


--
KHashmi316
------------------------------------------------------------------------
KHashmi316's Profile: http://www.excelforum.com/member.php...o&userid=10439
View this thread: http://www.excelforum.com/showthread...hreadid=374615

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import Data macro


try this macro, I am using inputbox which will prompt for complete
filename with path.
This filename with path is used inthe macro get the text contents
Sub IMPORT_DATA()

Cells.Select
Dim file_name As Variant
file_name = InputBox("enter the filename with complete file path")

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & file_path _
, Destination:=Range("A1"))
..Name = "10273764-eCOST_com_eZ_Affiliate_Program"
..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 = xlTextQualifierNone
..TextFileConsecutiveDelimiter = False
..TextFileTabDelimiter = False
..TextFileSemicolonDelimiter = False
..TextFileCommaDelimiter = False
..TextFileSpaceDelimiter = False
..TextFileOtherDelimiter = "|"
..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, 1, 1, 1, 1, 1, 1, 1, 1)
..TextFileTrailingMinusNumbers = True
..Refresh BackgroundQuery:=False
End With
ActiveWorkbook.Save

End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=374615

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import Data macro


anilsolipuram, thx for your help!

When I tried it, I got a:

"Compile Error: Valiable not found"

where "file_path" is highlighted in:

"Connection:= _
"TEXT;" & file_path _
, Destination:=Range("A1"))"

Also, how do I deal with this parameter from the original IMPORT-DATA:

..Name = "10273764-eCOST_com_eZ_Affiliate_Program"


-KH


--
KHashmi316
------------------------------------------------------------------------
KHashmi316's Profile: http://www.excelforum.com/member.php...o&userid=10439
View this thread: http://www.excelforum.com/showthread...hreadid=374615

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import Data macro


minor error, try now

Sub IMPORT_DATA()

Cells.Select
Dim file_name As Variant
file_name = InputBox("enter the filename with complete file path")

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & file_name _
, Destination:=Range("A1"))
..Name = "10273764-eCOST_com_eZ_Affiliate_Program"
..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 = xlTextQualifierNone
..TextFileConsecutiveDelimiter = False
..TextFileTabDelimiter = False
..TextFileSemicolonDelimiter = False
..TextFileCommaDelimiter = False
..TextFileSpaceDelimiter = False
..TextFileOtherDelimiter = "|"
..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, 1, 1, 1, 1, 1, 1, 1, 1)
..TextFileTrailingMinusNumbers = True
..Refresh BackgroundQuery:=False
End With
ActiveWorkbook.Save

End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=374615

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import Data macro


Worked like a charm -- thank you!

May I ask for one more tweak? In it's current form, the InputBox asks
for the filename with complete file path. Is it possible to design the
InputBox so that one can *Browse* for a file. Often I find it helpful to
type/paste in a simple directory path (e.g. C:\Excel_files\) and choose
the file I wish to import.

-KH


--
KHashmi316
------------------------------------------------------------------------
KHashmi316's Profile: http://www.excelforum.com/member.php...o&userid=10439
View this thread: http://www.excelforum.com/showthread...hreadid=374615



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import Data macro


I set the default filepath as "c:\" , macro will open file dialog to
select file.

try this macro


Sub IMPORT_DATA()

dim file_name as variant

Cells.Select



Application.DefaultFilePath = "C:\" 'Set default file path to root
file_name = Application.GetOpenFilename



With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & file_name _
, Destination:=Range("A1"))
..Name = "10273764-eCOST_com_eZ_Affiliate_Program"
..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 = xlTextQualifierNone
..TextFileConsecutiveDelimiter = False
..TextFileTabDelimiter = False
..TextFileSemicolonDelimiter = False
..TextFileCommaDelimiter = False
..TextFileSpaceDelimiter = False
..TextFileOtherDelimiter = "|"
..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, 1, 1, 1, 1, 1, 1, 1, 1)
..TextFileTrailingMinusNumbers = True
..Refresh BackgroundQuery:=False
End With
ActiveWorkbook.Save

End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=374615

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import data and macro Jambruins Excel Discussion (Misc queries) 5 October 24th 07 02:37 PM
Import Data with Macro or VBA sahafi Setting up and Configuration of Excel 0 September 1st 06 06:34 PM
Import Data Excel Macro [email protected] Excel Discussion (Misc queries) 3 August 23rd 06 02:11 PM
import data with macro chris_rip Excel Discussion (Misc queries) 0 July 18th 05 08:40 PM
import data using macro chris_rip Excel Discussion (Misc queries) 0 July 18th 05 08:32 PM


All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"