Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
creating csv file | Excel Discussion (Misc queries) | |||
Creating a New Macro | Excel Discussion (Misc queries) | |||
Creating a CSV File from.... | Excel Discussion (Misc queries) | |||
Need Help Creating A Macro | Excel Worksheet Functions | |||
assigned macro taking the name of file creating it. Please help. | Excel Programming |