Why Im I getting an error in code..

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why Im I getting an error in the partial code below??
Im trying to import a tezt file, but when I try to run it it highlights the
FName line and says the following messege: "Expected: line# or label or
statement or end of statement"

FName= F:\trial2.txt For Input As #1
Open FName For Input Access Read As #1
.........................
.........................
.........................


Thanks in advance
 
Why Im I getting an error in the partial code below??
Im trying to import a tezt file, but when I try to run it it highlights
the
FName line and says the following messege: "Expected: line# or label or
statement or end of statement"

FName= F:\trial2.txt For Input As #1

I am not sure what the For Input As #1 part is supposed to be doing... you
are just trying to assign the path to the variable, right?

FName = "F:\trial2.txt"

Note the quote marks.

Rick
 
Tried the quotations and still didnt work. Hey Rick I expanded on the code so
that u can look at why the For #1 statement does:
I think the #1 statmetnt is referred in the code in the line that states "
Line Input #1. See below


FName = "F:trial2.txt" For Input As #1
Open FName For Input Access Read As #1
.............
............
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) <> sp Then
WholeLine = WholeLine & sp
End If
 
Thanks dave I will look at that website shortly. I tried the quotations and
still didnt work.
 
Hey dave that is the website that I got my macro from.
So actually im not sure if thats gonna help me out any more
But thanks though. Any other ideas??
 
Better:

FName = "F:\trial2.txt"
Fnum = Freefile() ' gives next available buffer #
Open FName For Input As #Fnum
Do While Not EOF(Fnum)
Line Input #Fnum,WholeLine
....
....
Loop
Close #Fnum

Since you're only reading it, not really necessary to use the Access Read.

In a way you're assigning a file to a 'variable' when you do the open.
Picture the #1 or #Fnum as assigning a communication path (and more) to that
file.

The Freefile() function returns the next available number for such
operations - they can go from 1 to 255. It's best to use it, especially if
you are working with multiple files.
 
Thank you JLatham Ill give that a try.


JLatham said:
Better:

FName = "F:\trial2.txt"
Fnum = Freefile() ' gives next available buffer #
Open FName For Input As #Fnum
Do While Not EOF(Fnum)
Line Input #Fnum,WholeLine
...
...
Loop
Close #Fnum

Since you're only reading it, not really necessary to use the Access Read.

In a way you're assigning a file to a 'variable' when you do the open.
Picture the #1 or #Fnum as assigning a communication path (and more) to that
file.

The Freefile() function returns the next available number for such
operations - they can go from 1 to 255. It's best to use it, especially if
you are working with multiple files.
 
N.F.

Highjacking this to add to yesterday's post on Row Colors.

The code I posted works on one cell at a time only.

Try this amended code to allow a larger range to be selected and copied.

Sub copy_no_change()
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Selection
Set rng2 = Application.InputBox(Prompt:= _
"Select Any Cell to paste to", Type:=8)
rng2.Resize(rng1.Rows.Count, rng1.Columns.Count).Value _
= rng1.Value
rng1.ClearContents
End Sub


Gord
 
You're welcome - just the final touch to those that started down the path to
assist you before me.
 
Back
Top