View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
mike mike is offline
external usenet poster
 
Posts: 5
Default Import Macro in PERSONAL.XLS will not import to my main document

Hello,
I am a complete newb with Macros, FYI. I created a Macro in my
PERSONAL.XLS document that imports from an external file into my
worksheet. However, it only imports to the PERSONAL.XLS and won't
import to my main document. Can anybody help me out? Sorry if I
didn't word something correctly. Here is my code:

Sub ImportFromReceiptFile()

Dim RowNdx As Long
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer

Dim FName As String
Dim Sep As String

FName = "C:\temp\ImportFile.txt"
Sep = "|"

Application.ScreenUpdating = False

SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row

Open FName For Input Access Read As #1

While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) < Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos = 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend

Application.ScreenUpdating = True
Close #1

End Sub