Macros works on Personal.XLSB, but when transfer to VBA this debugs.

kitsa

Board Regular
Joined
Mar 4, 2016
Messages
111
Office Version
  1. 365
  2. 2016
Hi Guys,
I have created a Macro in my personal macro, but when I transfer to VBA it doesn't work and debugs, can someone please explain why this is happening. It stops when it gets to the bold "Cells.Select"

HTML:
Private Sub CommandButton2_Click()
Application.DisplayAlerts = False
   Dim dmy As String
   dmy = Format((Now), "yyyy")
    ChDir _
        "F:\GuyM\TinaA\My Documents\ESS PROGRESS CLAIMS"
    ActiveWorkbook.SaveAs Filename:= _
         "C:\Users\kitsas\Desktop\ESS Contract Administration Reconciliation\Baranagaroo\" & "Barangaroo " & " " & MonthName(Month(Now)) & " " & dmy & ".xls" _
        , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("P19").Select
    Application.CutCopyMode = False
    Columns("L:P").Select
    Selection.ClearContents
    Columns("A:A").Select
    Selection.ClearContents
    Range("L17").Select
    Sheets("Invoice").Select
    Cells.Select
    Range("B1").Activate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B14").Select
    Range("H13:H17").Select
    Range("D13:D17").Select
    Sheets("ESS Inv Data Entry").Select
    Application.CutCopyMode = False
    ActiveWindow.SelectedSheets.Delete
    Sheets("Summary").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Description").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Control Sheet").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Estimate").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Claim Summary").Select
    Range("M22").Select
    ActiveWindow.SmallScroll Down:=-21
    ActiveSheet.Shapes.Range(Array("Signed Contract")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("Payment Schedule")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("Send Email")).Select
    Selection.Delete
    ActiveSheet.Shapes.Range(Array("Print Document")).Select
    Selection.Delete
    Range("M13").Select
    Columns("I:M").Select
    Selection.ClearContents
    Range("L2").Select
    ActiveWindow.SmallScroll Down:=-15
    ActiveWorkbook.Save
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Users\kitsas\Desktop\ESS Contract Administration Reconciliation\Baranagaroo\Barangaroo Invoice.xls" _
        , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
    Range("L30").Select
    Sheets("Claim Summary").Select
    ActiveWindow.SmallScroll Down:=-12
    ActiveWorkbook.Save
    Range("M10").Select
'---------------------------------------
'Send Email
  
 Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    
   
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Hi Greg," & _
              "
" & "As attached, is your invoice for review, please confirm via email or payment schedule once evaluated for reconciliation purpose." & _
              "
" & _
              "
" & _
              "
" & "If you have any issues please do not hesitate to contact me." & _
              "
"
    On Error Resume Next
    With OutMail
        .display
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "Service"
        .HTMLBody = strbody & "" & .HTMLBody
               
        .Importance = 2 'Or olImprotanceHigh Or olImprotanceLow
        .display
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
    Set OutLookMess = Nothing
    Set OutLookNSpace = Nothing
ActiveWorkbook.Close
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Re: Macrs works on Personal.XLSB, but when transfer to VBA this debugs.

Don't have Excel at the moment, but try the modified code....ON A TEST WORKBOOK !!!

Code:
Private Sub CommandButton2_Click()
Application.DisplayAlerts = False
   Dim dmy As String
   dmy = Format((Now), "yyyy")
    ChDir _
        "F:\GuyM\TinaA\My Documents\ESS PROGRESS CLAIMS"
    ActiveWorkbook.SaveAs Filename:= _
         "C:\Users\kitsas\Desktop\ESS Contract Administration Reconciliation\Baranagaroo\" & "Barangaroo " & " " & MonthName(Month(Now)) & " " & dmy & ".xls" _
        , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
    With ActiveSheet.UsedRange
    .Value = .Value
    End With
    Columns("A:A,L:P").ClearContents
    With Sheets("Invoice").Range("B1")
    .Value = .Value
    End With
    Sheets(Array("ESS Inv Data Entry", "Summary", "Description", "Control Sheet", "Estimate")).Delete
    Sheets("Claim Summary").Range("M22").Select
    With ActiveSheet
    .Shapes.Range(Array("Signed Contract")).Delete
    .Shapes.Range(Array("Payment Schedule")).Delete
    .Shapes.Range(Array("Send Email")).Delete
    .Shapes.Range(Array("Print Document")).Delete
    End With
    Columns("I:M").ClearContents
    ActiveWorkbook.Save
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Users\kitsas\Desktop\ESS Contract Administration Reconciliation\Baranagaroo\Barangaroo Invoice.xls" _
        , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
'---------------------------------------
'Send Email
  
 Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    
   
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Hi Greg," & _
              "" & _
"As attached, is your invoice for review, please confirm via email or payment schedule once evaluated for reconciliation purpose." & _
              "" & _
              "" & _
              "" & "If you have any issues please do not hesitate to contact me." & _
              ""
    On Error Resume Next
    With OutMail
        .display
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "Service"
        .HTMLBody = strbody & "" & .HTMLBody
               
        .Importance = 2 'Or olImprotanceHigh Or olImprotanceLow
        .display
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
    Set OutLookMess = Nothing
    Set OutLookNSpace = Nothing
ActiveWorkbook.Close
End Sub
 
Last edited:
Upvote 0
Re: Macrs works on Personal.XLSB, but when transfer to VBA this debugs.

Thanks Michael,
It comes up with an error when it hits "Columns("A:A,L:P").ClearContents". Somehow it's stopping from it going further.

Thanks
Kitsa
 
Upvote 0
Re: Macrs works on Personal.XLSB, but when transfer to VBA this debugs.

Sorry...:oops:
change it to

Code:
[color=red]Range[/color]("A:A,L:P").ClearContents
 
Upvote 0
Re: Macrs works on Personal.XLSB, but when transfer to VBA this debugs.

Hello Michael,

Thanks it worked, but the ".Value = .Value" changes to value of "Currency" format, how do I make the format to be "Accounting"?
 
Upvote 0
Re: Macrs works on Personal.XLSB, but when transfer to VBA this debugs.

Reformat the cells...the code does not change the format of the cells as it is now !!
Add this line after the value = .value line
Code:
.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
 
Upvote 0

Forum statistics

Threads
1,221,707
Messages
6,161,411
Members
451,704
Latest member
rvan07

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top