Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with VBA code to access a word file from excel.

Status
Not open for further replies.

gk759

IS-IT--Management
Jun 28, 2001
46
US
Hi,

I have this worksheet that imports a file- bom.rpt. Now i want to replace this file with an excel or word document.
I made changes to the code accordingly but when it imports it works in the begining but later the data becomes garbelled.

I have little practice with VBA and the using series book for Excel hasnt helped me solve this problem.If soemone has a solution , I would reallly apprciate.

here is the part where the worksheet accesses the external data file.

Sub Update_BM_Data()
'
' Define variables "fname" and "fpath"
'
' "fpath" is assigned the current path for the MP workbook.
' "fname" is the complete file name, path and type of the target for
' the data query used to import the Business Works data.
' A complete file named "Bom.rpt" in the same directory as the
' MP workbook.
'
Dim fname
Dim fpath
fpath = ActiveWorkbook.Path
fname = "TEXT;" & fpath & "\Bom.rpt"
'
' Select and clear the appropriate sheet in the MP workbook
'
Sheets("BOM data").Select
Clearsheet
'
' Import the bw data
'
With ActiveSheet.QueryTables.Add(Connection:=fname, Destination:=Range("A1"))
.Name = "Bom"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(15, 32, 10, 11)
.Refresh BackgroundQuery:=False
End With
Look in forward to a response,

Thanks,

Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top