You are only changing the file name if the current file name is 15 characters in length. Can you confirm that the file name is this long?
Main Topics
Browse All TopicsHello
I have a macro that is not working as expected.The macro is supposed to take, the original file name and add a sequence number to the existing filename. Is is supposed to sequence up to 3 versions. After the macro checks the file name , it emails it as an attachment , then reformats the spreadsheet to a different format then saves it to my desktop. The first first sequence works great, giving the file its sequence name. saves it to a shared folder, emails it and reformats it and saves it to my desktop. So when I open the first sequence file, and run the macro on it , it just sends an email with no attachment and doesn't save the file no place with the new sequenced name.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi Lorena
Ok on other thing. As you can see the fist part of the code saves the file with a new name. I then reformat the file and give it a little bit of a change,I was able to do this before by using dealmac" & format(Date, "yyyymmdd") & ".xls", or deal " & format(Date, "yyyymmdd") & ".csv", for the seconf format. Not that I am incrementing, is it possible to reuse the file name under from the first saving. So the first file will be named dealmac20091006001. I save the file to the shared drive, send it then reformat it. How can I easily tell it to save the file deal20091006001or --02 or 003 ?
Hi Lorenda
Sort of , the first part saves the code saves the file as dealmac20091006 + the increment 001,002 or 003 as format xls. the 2nd part of the macro, reformats the file, adding columns etc. the I want to save it as deal20091006 plus the increment.
I am using this
ActiveWorkbook.SaveAs FileName:="C:\Documents and Settings\rsernowski.R-SERN
that is not working right as it is duplicating the word deal. Actually I need it to remove the word MAC. Hope this makes sense
Oops - this was my fault. The Full Name should just be Name
Dim a As String
a = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) 'removes the .xls
a = Replace(a, "mac", "") ' finds and removes the mac
a = a & ".csv" ' adds the csv
ActiveWorkbook.SaveAs FileName:="C:\Documents and Settings\rsernowski.R-SERN
Hi,
The code is there on that line
here is is:
'
' Mac_Trades_Correct Macro
'
Dim FileName As String
Dim wb1 As Workbook
Dim Row As Long
Dim OutApp As Object
Dim OutMail As Object
Dim Today As Date
Dim ie As Object
Dim ErrorCount As String
Dim currentFileName As String
Dim newFileName As String
Dim msgReply As Long
Dim incrementNumber As Integer
Dim a As String
currentFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
If Len(currentFileName) = 15 Then
'Changes have not yet been saved
newFileName = currentFileName & "001"
Select Case MsgBox("The file will be saved as " & newFileName & ".xls", _
vbOKCancel, "Save As Filename")
Case vbOK
'Save the file
Application.EnableEvents = False
' ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.P
' & newFileName & ".xlsm"
ActiveWorkbook.SaveAs FileName:="\\Share_folder\
& newFileName & ".xls", FileFormat:=xlExcel8
Application.EnableEvents = True
Case vbCancel
'Do nothing (exit the procedure).
Exit Sub
End Select
ElseIf Len(currentFileName) = 18 Then
'Changes have already been saved at least once.
incrementNumber = Right(currentFileName, 1)
If incrementNumber = 1 Or incrementNumber = 2 Then
newFileName = Left(currentFileName, Len(currentFileName) - 1) _
& (incrementNumber + 1)
Select Case MsgBox("The file will be saved as " & newFileName _
& ".xls", vbOKCancel, "Save As Filename")
'& ".xlsm", vbOKCancel, "Save As Filename")
Case vbOK
Application.EnableEvents = False
ActiveWorkbook.SaveAs FileName:="\\Share_folder\
& newFileName & ".xls", FileFormat:=xlExcel8
Application.EnableEvents = True
Case vbCancel
'Do nothing (exit the procedure).
Exit Sub
End Select
Else
MsgBox "You cannot save any new revisions to this file.", vbOKOnly
End If
End If
'Cancel the native Save As dialog box.
If SaveAsUI = True Then Cancel = True
'Print the work Sheet
Set wb1 = ActiveWorkbook
ActiveSheet.PageSetup.Prin
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
ExecuteExcel4Macro "PRINT(1,,,1,,FALSE,,,,,,2
'send the trade ticket to Mackenzie'
If MsgBox("Click OK to EMail, Cancel to STOP.", vbOKCancel) = vbCancel Then Exit Sub
Set OutApp = CreateObject("Outlook.Appl
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With wb1
On Error Resume Next
With OutMail
' .to = ""
' .CC = ""
.BCC = "rsernowski@gmail.com"
.Subject = " CANCEL AND CORRECT"
.Body = " CANCEL AND CORRECT. File name prior to this CANCEL and CORRECT " & currentFileName
.Attachments.Add wb1.FullName
'wb1.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.send 'or use .Display
End With
On Error GoTo 0
End With
'ActiveWorkbook.Close SaveChanges:=False
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "The file was successfully sent "
'End With
'Reformat the file to Mellon Format
Set wb1 = ActiveWorkbook
With wb1
'Add columns and format columns
Columns("F:F").Hidden = False
Columns("J:J").Hidden = False
Columns("R:R").Hidden = False
Columns("S:S").Hidden = False
Columns(12).insert
Columns(14).insert
Columns(15).insert
Columns(18).insert
Columns(22).insert
Columns(23).insert
Columns(24).insert
Columns(25).insert
Columns(28).insert
Columns(29).insert
Columns(30).insert
Columns(31).insert
Columns(32).insert
Columns(33).insert
Columns(34).insert
Columns(35).insert
Columns("AB:AI").ColumnWid
Columns("AR:AY").ColumnWid
Columns("AL:AO").ColumnWid
Columns("V:Y").ColumnWidth
Columns("R:R").ColumnWidth
Columns("N:O").ColumnWidth
Columns("L:L").ColumnWidth
Columns("C:C").EntireColum
Columns("U:U").EntireColum
Columns("D:E").NumberForma
Columns("D:E").EntireColum
Columns("I:I").NumberForma
Columns("H:H").NumberForma
Columns("I:I").EntireColum
Columns("M:M").NumberForma
Columns("O:O").NumberForma
Columns("Q:Q").NumberForma
Columns("S:S").NumberForma
Columns("T:T").EntireColum
Columns("AA:AA").NumberFor
Columns("L:S").EntireColum
'First Delete the Header from Toogood
Rows("1:2").Delete
End With
With ActiveSheet
a = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.FullNam
a = Replace(a, "Mac", "") ' finds and removes the mac
a = a & ".csv" ' adds the csv
ActiveWorkbook.SaveAs FileName:="C:\Documents and Settings\rsernowski.R-SERN
'ActiveWorkbook.SaveAs FileName:="\\Share_folder\
' wb1.Close SaveChanges:=False
'Open the webpage
' Set ie = CreateObject("Internetexpl
'ie.Visible = True
'ie.Navigate "https://workbench.com/fil
End With
End Sub
Hi Lorenda
Very nice , Thank you. I will accept as solution but perhaps you can help me with the bottom part of the code
Open the webpage
' Set ie = CreateObject("Internetexpl
'ie.Visible = True
'ie.Navigate "https://workbench.com/fil
End With
End Sub
I have posted this question but as of yet no reply. when the conversion to csv is done, a secure website opens up. I put in user ID and password, and the site opens to a page where the user can browse to the desktop and locate the csv file we just saved. Works, but is it possible to save the file into memory, then when the webpage opens , the user focuses on the browse box and presses CTRL+V to paste in the path?
Business Accounts
Answer for Membership
by: lorendaPosted on 2009-10-06 at 08:01:48ID: 25505827
Can you also post the code behind the
,,,TRUE,,F ALSE)"
ExecuteExcel4Macro "PRINT(1,,,1,,FALSE,,,,,,2