Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create Excel formatted text file with generated text as file name in a macro

Posted on 2003-03-18
3
Medium Priority
?
146 Views
Last Modified: 2010-05-01
I have >100 excel files to save as .txt files and this field changes in each one so I'm trying to create a macro to do it and use the field in the file name...

This is an example of the data I have:

A1 = 01234
A2 = ABCDE
in A3 is =CONCATENATE(A1,A2) giving 01234ABCDE
I want to be able to save this file as 01234ABCDE.txt (text file TAB delimited)
where 01234 is different every time.

I tried to copy the concatenated field to a text field using paste special:
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

and then tried copying the value to the save box but it gave me the same value again and again.
ActiveWorkbook.SaveAs Filename:="c:\01234ABCDE.txt", FileFormat:=xlText, CreateBackup:=False
I want it to look at A3.

Stuck and hope you can help please :-/


0
Comment
Question by:Mellissa
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
ID: 8158754
Hi Mellissa,

Use ActiveWorkbook.SaveAs FileName:=ActiveSheet.Range("A3"), FileFormat:=xlText, CreateBackup:=False

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
 

Author Comment

by:Mellissa
ID: 8158866
Thank you,
Tried, tested and works a treat

It always looks easy when someone else shows you how.

.
0
 
LVL 3

Expert Comment

by:DocM
ID: 8158873

Sub SaveFile()
 Path = "c:\"
 
 strfilename = Path & Range("A3").Value & ".txt"
 
 While Dir(strfilename) <> ""
 
  Number = Range("A1").Value + 1
  Number = Format(Number, "00000")
  Range("A1").Value = "'" & CStr(Number)
 
  strfilename = Path & Range("A3").Value & ".txt"
 Wend
 
  ActiveWorkbook.SaveAs Filename:=strfilename, FileFormat:=xlText, _
        CreateBackup:=False
 
End Sub
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question