![]() |
Creating a txt file from a macro
I am trying to create a simple text file that contains some
information from an Excel sheet. I am trying to create an Excel Add-In that will run the macro that I have written to create this file. Everything works fine if I specify a path to the text file, but I would like to allow the user to enter the path and name for the file. I am trying to use the FileDialog object, which seems to work ok if the type specifed is anything but msoFileDialogSaveAs, which I believe is what I need. When I specify this type, Excel crashes on me, without supplying any information about why. Does anyone have any idea why this might happen, or how I can get around it? |
Creating a txt file from a macro
Beth,
Try something like: MyTextFileName = Application.GetSaveAsFilename Opens a save as dialog box and returns a string representing the location and name ie. C:\My Documents\TextFile1.txt It can further be specified to text and given an initial name like 'Set the initial directory to start in ChDir ("C:\My Documents\") 'Get the name of the text file MyTextFileName = Application.GetSaveAsFilename("test.txt", "Text Files, *.txt") 'Check to make sure a name has been entered If MyTextFileName = "False" Then MsgBox Prompt:="File Not Saved, No Name Specified" Exit Sub End If Dan E "Beth" wrote in message m... I am trying to create a simple text file that contains some information from an Excel sheet. I am trying to create an Excel Add-In that will run the macro that I have written to create this file. Everything works fine if I specify a path to the text file, but I would like to allow the user to enter the path and name for the file. I am trying to use the FileDialog object, which seems to work ok if the type specifed is anything but msoFileDialogSaveAs, which I believe is what I need. When I specify this type, Excel crashes on me, without supplying any information about why. Does anyone have any idea why this might happen, or how I can get around it? |
Creating a txt file from a macro
Thanks Dan. That does exactly what I need.
"Dan E" wrote in message ... Beth, Try something like: MyTextFileName = Application.GetSaveAsFilename Opens a save as dialog box and returns a string representing the location and name ie. C:\My Documents\TextFile1.txt It can further be specified to text and given an initial name like 'Set the initial directory to start in ChDir ("C:\My Documents\") 'Get the name of the text file MyTextFileName = Application.GetSaveAsFilename("test.txt", "Text Files, *.txt") 'Check to make sure a name has been entered If MyTextFileName = "False" Then MsgBox Prompt:="File Not Saved, No Name Specified" Exit Sub End If Dan E "Beth" wrote in message m... I am trying to create a simple text file that contains some information from an Excel sheet. I am trying to create an Excel Add-In that will run the macro that I have written to create this file. Everything works fine if I specify a path to the text file, but I would like to allow the user to enter the path and name for the file. I am trying to use the FileDialog object, which seems to work ok if the type specifed is anything but msoFileDialogSaveAs, which I believe is what I need. When I specify this type, Excel crashes on me, without supplying any information about why. Does anyone have any idea why this might happen, or how I can get around it? |
All times are GMT +1. The time now is 02:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com