Making a text file with identical name & Path

anichols

Board Regular
Joined
Mar 11, 2021
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I have some VBA that is creating a pipe delimited text file, but I am struggling to get the name correct. I have managed to save it in the same location, but attempting to name it the same as the excel file has failed. Any help would be greatly appreciated.

VBA Code:
Sub PipeDelimited() 
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook

Open thisWb.Path & "\new workbook.txt" For Output As 1  'Change this path



rowno = 1
colcount = Application.CountA(ActiveSheet.Rows(1))
While ActiveSheet.Cells(rowno, 1) <> ""
    dataout = "" 'start of line
    For C = 1 To colcount
        If C <> colcount Then
            dataout = dataout & "" & Trim(ActiveSheet.Cells(rowno, C)) & "|" 
        Else
            dataout = dataout & "" & Trim(ActiveSheet.Cells(rowno, C)) & ""
        End If
    Next C
    Print #1, dataout
    rowno = rowno + 1
Wend
Close #1
End Sub

Thank you,

Drew
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I have tried this, hoping to get closer, but I get run time error 438.

VBA Code:
Open thisWb.Path & "\" & thisWb & ".txt" For Output As 1  'Change this path
 
Upvote 0
VBA Code:
    Open Left(thisWb.FullName, InStrRev(thisWb.FullName, ".")) & "txt" For Output As #1
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top