save as txt saves different tab, why???

G

Guest

hello

I have big workbook with many macros helping people to sort out some
complicated document. anyway last step after document has been edited, one
tab needs to be saved as txt file. I wrote a macro that does it (it is run
from a button on tab called 'summary'). tab that needs to be saved as txt is
called 'output'.
tab 'output' contains very long lines over 255 characters long.
problem is macro saves different tab sometimes and I have no idea why.
macro is simple and goes like that:

Dim fname '- define file name
fname = "cardex" & Mid(Worksheets("output").Range("a2"), 23, 8) & ".txt"

Dim cpath '-define path - range A7 contains path
cpath = Worksheets("summary").Range("a7")

Sheets("output").Select

ActiveWorkbook.SaveAs Filename:=cpath & fname, FileFormat:=xlText, _
CreateBackup:=False


any ideas greatly appreciated
 
D

Dave Peterson

Your posted pseudo code looks ok to me. I'd check to see if you were actually
selecting the correct worksheet first.

I'd do this instead.

your dim's here
your assignments here

worksheets("output").copy 'to a new workbook
activeworkbook.saveas ....
activeworkbook.close savechanges:=false
 
G

Guest

thanks, it does the trick. I still wonder why my 'pseudocode' was saving
wrong tab sometime. is below line ambiguous maybe?

sheets("output").select ???

just out of curiosity, some codes are referred to as 'pseudocodes', what is
the difference?

thanks again
 
D

Dave Peterson

I didn't see anything wrong that popped out when I looked at your code. I don't
have a guess why the code that you posted would fail--maybe there was something
in the code that you didn't post????

Psuedo code is false code--it's not ready to just copy and paste into a module
and run as-is.

It can include as much detail (or as few details) as the author wants/needs.

Open a workbook file
work on the pricing sheet
Update the values for customer xxx by 5% to a maximum of 280% of the cost.
Create a report sheet for those parts
Save the workbook file as a new name
Close the workbook

is a pretty high level of psuedo code. It may be enough for one person to
continue to develop the project. Other people may want to add more details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top