forrestgump
Registered User.
- Local time
- Today, 06:01
- Joined
- Aug 14, 2017
- Messages
- 10
Hi all,
I am trying to open a blank excel workbook from MS Access and then bring in the data from another excel file. I need to do this because of the file i need to open is a csv file and if I open it normally i lose leading zeros. I have tried the below code but i cant get it to work. Any help would be greatly appreciated.
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\jsmith\Documents\002_Department.csv", Destination:=Range( _
"$A$1"))
.Name = "002_Department"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
I am trying to open a blank excel workbook from MS Access and then bring in the data from another excel file. I need to do this because of the file i need to open is a csv file and if I open it normally i lose leading zeros. I have tried the below code but i cant get it to work. Any help would be greatly appreciated.
Code:
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Set xlApp = New Excel.Application
Set xlWB = xlApp.Workbooks.Add
xlApp.Visible = True
xlApp.Sheets("Sheet1").Select
xlApp.Sheets("Sheet1").name = strFileName
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\jsmith\Documents\002_Department.csv", Destination:=Range( _
"$A$1"))
.Name = "002_Department"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With