PDA

View Full Version : Button - Create/Fill/Export



anime4tw
10-08-2013, 11:29 AM
Hello all!!

I've been working on trying to record a macro, that is NOT working. Although I'm not super familiar with VBA, I do understand the basics of programming.
I was hoping for some help.


My goal is to create a button that will:

1. Create a new sheet, in current document (name is not important)
2. In said sheet will fill in a formula based on values from sheet one
3. Export (Save As...) file as a .csv ---- Filename structure: twitterDDMMYYYY.csv ---- This is where I'm running into issues. The DD/MM/YYYY are in THREE fields in the original sheet.
4. Delete the sheet after it's saved
5. Display a pop-up "Successful: <<Path/FileName>> has been created." OR "Error: <<error_code>>"


I don't have any of the VBA code anymore, as it seems to have all been deleted (yay for working on a public network corporate computer...*sigh* -- Finally have my own one now. Shouldn't have any issues)


Just so that I'm not just asking someone to code something for me, my issues are.

1. Do I need to create a unique sheet name, and if so... Would a loop be the best option for this? Any examples?
2. I believe the Macro did an excellent job of this.
3. THIS is where I was having tons of issues .... I was getting an error saying 'Are you sure you want to save in this format, formatting may not be compatible...blahblahblah'. Have no clue how to get the specific values from a cell into the filename, and just click through any errors that are created.
4. I believe the macro just created a simple 'close.sheet' function?
5. Not necesary, but would be nice to know that the script ran, and was either successful for Died~ LOL


Anyways, any and all help would be grateful, I'll continue to putter away at it, and try to find some KB documents that I can teach myself with.



Thanks everyone!!!

SamT
10-09-2013, 06:10 AM
Format Warning:
Application.DisplayAlerts = False. Be sure to set it True and end of sub.


Filename = "Twitter" & Range("A1") & Range("B1") & Range"C1")

Instead of Formulas, it is probably easier to us VBA to fill the values on Sheet twitter.

Dim Sht As WQorkSheet
Set Sht = Sheets("Sheet1")

With Sheets("Twitter
.Range("A1") = Sht.Range("B1")
Range("F6") = Sht.Range("B2") + Sht.Range("X99")
End With

Alternately, Create a Template sheet for "twittter" with all formatting and formulas then Copy it and SaveAs, etc

Sheets("Template").Copy.Before:=Sheets("Sheet1`")
'Rename
Sheets(Sheets.Count).Name = "Twitter"
'or rename
Sheets"(Template(2)").Name = "twitter"