Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating csv file Julie Excel Discussion (Misc queries) 3 March 23rd 09 08:51 PM
Creating a New Macro SharonJo Excel Discussion (Misc queries) 1 April 4th 08 01:27 AM
Creating a CSV File from.... Nimish Excel Discussion (Misc queries) 0 October 4th 06 10:30 PM
Need Help Creating A Macro LJ Owen Excel Worksheet Functions 1 March 2nd 05 01:52 PM
assigned macro taking the name of file creating it. Please help. Dave Peterson[_3_] Excel Programming 1 July 31st 03 03:49 AM


All times are GMT +1. The time now is 10:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"