T
the_golden_gunman
Hi I have a problem with Excel that I would like to use a Macro to do.
I am unfamilar with the syntax used in Excel so this task is proving
to be somewhat tricky.
I would like to copy all entries from one colum into a text file.
Additionally, I would like to create a series of sub directories in
the location that the file is saved that correspond to the columns
extracted via the text file.
How would I go about writng a Macro to perform such a task? This is as
far as I have got:
Sub ExportToPRN()
Dim FName As String
Dim WholeLine As String
Dim FNum As Integer
Dim myRange As Range
Dim myCell As Range
Dim myName As String
myName = ActiveWorkbook.FullName
FName = Application.GetSaveAsFilename( _
Replace(myName, ".xls", ".prn"))
On Error GoTo EndMacro:
FNum = FreeFile
Open FName For Output Access Write As #FNum
Set myRange = Range("C1:C99")
WholeLine = ""
For Each myCell In myRange
MkDir PathForTextFile & "\" & CellValue
WholeLine = WholeLine & "\" & myCell.Text & vbNewLine
Next myCell
WholeLine = Left(WholeLine, Len(WholeLine) - 1)
Print #FNum, Trim(WholeLine)
EndMacro:
On Error GoTo 0
Close #FNum
End Sub
I have tried removing the "WholeLine = WholeLine & "\" & myCell.Text &
vbNewLine " line, but without success.
I am unfamilar with the syntax used in Excel so this task is proving
to be somewhat tricky.
I would like to copy all entries from one colum into a text file.
Additionally, I would like to create a series of sub directories in
the location that the file is saved that correspond to the columns
extracted via the text file.
How would I go about writng a Macro to perform such a task? This is as
far as I have got:
Sub ExportToPRN()
Dim FName As String
Dim WholeLine As String
Dim FNum As Integer
Dim myRange As Range
Dim myCell As Range
Dim myName As String
myName = ActiveWorkbook.FullName
FName = Application.GetSaveAsFilename( _
Replace(myName, ".xls", ".prn"))
On Error GoTo EndMacro:
FNum = FreeFile
Open FName For Output Access Write As #FNum
Set myRange = Range("C1:C99")
WholeLine = ""
For Each myCell In myRange
MkDir PathForTextFile & "\" & CellValue
WholeLine = WholeLine & "\" & myCell.Text & vbNewLine
Next myCell
WholeLine = Left(WholeLine, Len(WholeLine) - 1)
Print #FNum, Trim(WholeLine)
EndMacro:
On Error GoTo 0
Close #FNum
End Sub
I have tried removing the "WholeLine = WholeLine & "\" & myCell.Text &
vbNewLine " line, but without success.