![]() |
filedialog in conjunction with printing to a text file
Hi I'm trying to adapt a macro that "saves" a spreadsheet as pipe-delimited
text. The macro I've found on the web does what it says on the tin, but has a hard-coded file name, Open "C:data.txt" For Output As #1 and at a certain point in the macro, it use the line Print #1, CurrTextStr to save the data. I was hoping to find a way to get the user to detemine the output path/filename rather than having it hard-coded, but I just don't understand the filedialog syntax well enough to make it work. Can anyone help with this? Many thanks, Geoff. |
filedialog in conjunction with printing to a text file
Dim myFileName As Variant
myFileName = Application.GetSaveAsFilename _ (InitialFileName:="C:\myfile.txt", _ filefilter:="Text Files, *.txt") if myfilename = false then exit sub 'user hit cancel end if .... open myfilename for output as #1 ... print #1, currtextstr ====== You don't need the initialfilename if you don't want it. Geoff C wrote: Hi I'm trying to adapt a macro that "saves" a spreadsheet as pipe-delimited text. The macro I've found on the web does what it says on the tin, but has a hard-coded file name, Open "C:data.txt" For Output As #1 and at a certain point in the macro, it use the line Print #1, CurrTextStr to save the data. I was hoping to find a way to get the user to detemine the output path/filename rather than having it hard-coded, but I just don't understand the filedialog syntax well enough to make it work. Can anyone help with this? Many thanks, Geoff. -- Dave Peterson |
filedialog in conjunction with printing to a text file
Many thanks, that was perfect.
Geoff. "Dave Peterson" wrote: Dim myFileName As Variant myFileName = Application.GetSaveAsFilename _ (InitialFileName:="C:\myfile.txt", _ filefilter:="Text Files, *.txt") if myfilename = false then exit sub 'user hit cancel end if .... open myfilename for output as #1 ... print #1, currtextstr ====== You don't need the initialfilename if you don't want it. Geoff C wrote: Hi I'm trying to adapt a macro that "saves" a spreadsheet as pipe-delimited text. The macro I've found on the web does what it says on the tin, but has a hard-coded file name, Open "C:data.txt" For Output As #1 and at a certain point in the macro, it use the line Print #1, CurrTextStr to save the data. I was hoping to find a way to get the user to detemine the output path/filename rather than having it hard-coded, but I just don't understand the filedialog syntax well enough to make it work. Can anyone help with this? Many thanks, Geoff. -- Dave Peterson |
All times are GMT +1. The time now is 09:55 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com