?
Solved

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

Posted on 2003-03-18
3
Medium Priority
?
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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

770 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