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

I am working on creating a macro that takes text data and import it into an
existing worksheet. To do this, I normally using the Import Data wizard.
Since I do this several times a day, I am trying to create a macro that will
allow me to select the text file and select a cell placement for the data
once the text files is created. I have most of the code created, but cannot
get it to pause at the file open dialog box or the cell range box. Are there
specific codes I need to use to get this macro to do this? files into Excel
from Word several times a day.

With ActiveSheet.QueryTables.Add(Connection:="Text Files (*.txt), *.txt", _
Destination:=Range("A2"))
.Name = "subcount"
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

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

Try this for getting the file name
Sub GetFile()
Dim File1 As String

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Title = "Please Select Text File to Import"
If .Show Then
File1 = .SelectedItems(1)
MsgBox File1
Else
MsgBox "User Clicked Cancel"
End If
End With
End Sub

then in the activesheet.querytables.add, connection = File1

Charles Chickering

Miasha wrote:
I am working on creating a macro that takes text data and import it into an
existing worksheet. To do this, I normally using the Import Data wizard.
Since I do this several times a day, I am trying to create a macro that will
allow me to select the text file and select a cell placement for the data
once the text files is created. I have most of the code created, but cannot
get it to pause at the file open dialog box or the cell range box. Are there
specific codes I need to use to get this macro to do this? files into Excel
from Word several times a day.

With ActiveSheet.QueryTables.Add(Connection:="Text Files (*.txt), *.txt", _
Destination:=Range("A2"))
.Name = "subcount"
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub


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

Thanks very much. Just trying to figure out where in the code to place this
string. It seems like it should be placed after the With
ActiveSheet.QueryTables.Add... line. When I place it at the beginning, I get
a 'Method Range of object' error message.

"Die_Another_Day" wrote:

Try this for getting the file name
Sub GetFile()
Dim File1 As String

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Title = "Please Select Text File to Import"
If .Show Then
File1 = .SelectedItems(1)
MsgBox File1
Else
MsgBox "User Clicked Cancel"
End If
End With
End Sub

then in the activesheet.querytables.add, connection = File1

Charles Chickering

Miasha wrote:
I am working on creating a macro that takes text data and import it into an
existing worksheet. To do this, I normally using the Import Data wizard.
Since I do this several times a day, I am trying to create a macro that will
allow me to select the text file and select a cell placement for the data
once the text files is created. I have most of the code created, but cannot
get it to pause at the file open dialog box or the cell range box. Are there
specific codes I need to use to get this macro to do this? files into Excel
from Word several times a day.

With ActiveSheet.QueryTables.Add(Connection:="Text Files (*.txt), *.txt", _
Destination:=Range("A2"))
.Name = "subcount"
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub



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

Try it like this. I've never used the QueryTables before so that might
be where the wrong syntax is. Let me know what line you get the error
on, if you still get the error.

Charles

Dim File1 As String

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Title = "Please Select Text File to Import"
If .Show Then
File1 = .SelectedItems(1)
MsgBox File1
Else
MsgBox "User Clicked Cancel"
End If
End With

With ActiveSheet.QueryTables.Add(Connection:=File1 _
Destination:=Range("A2"))
.Name = "subcount"
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

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

I get the error on this code:
"With ActiveSheet.QueryTables.Add(Connection:=File1 _
Destination:=Range("A2"))"

"Die_Another_Day" wrote:

Try it like this. I've never used the QueryTables before so that might
be where the wrong syntax is. Let me know what line you get the error
on, if you still get the error.

Charles

Dim File1 As String

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Title = "Please Select Text File to Import"
If .Show Then
File1 = .SelectedItems(1)
MsgBox File1
Else
MsgBox "User Clicked Cancel"
End If
End With

With ActiveSheet.QueryTables.Add(Connection:=File1 _
Destination:=Range("A2"))
.Name = "subcount"
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub


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
Macro to Open the Menu Data,Refresh Data,filename,import Bob Excel Programming 0 February 11th 06 04:51 PM
Macro to import data Gerald[_2_] Excel Programming 2 August 12th 05 01:45 PM
Run a macro after data Import Fred[_24_] Excel Programming 1 July 29th 05 09:30 AM
import data with macro chris_rip Excel Discussion (Misc queries) 0 July 18th 05 08:40 PM
Import Data macro KHashmi316 Excel Programming 6 May 27th 05 10:07 PM


All times are GMT +1. The time now is 03:51 AM.

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

About Us

"It's about Microsoft Excel"