Hi All,
Can someone please assist by explaining why the section of code marked in red (see below) is not "executing/running"and how can I correct the problem.
I have no real programming experience so I am stuck. I tried googling for a solution but this was unproductive.
I ran the section of code on its own in a new workbook and it worked fine.
The rest of the code in the macro works fine.
Thank you
Dave Rapson
Can someone please assist by explaining why the section of code marked in red (see below) is not "executing/running"and how can I correct the problem.
I have no real programming experience so I am stuck. I tried googling for a solution but this was unproductive.
I ran the section of code on its own in a new workbook and it worked fine.
The rest of the code in the macro works fine.
Thank you
Dave Rapson
Code:
Sub SaveInvoice()
Application.ScreenUpdating = False
Dim strFilename, strDirname, strPathname, strDefpath As String
With ActiveSheet
On Error Resume Next ' If directory exist goto next line
strDirname = Format([Date], "yyyy") ' New directory name
strFilename = [To] & "-" & Format(Date, "yyyymmdd") & "-" & Format([InvNo], "000") & [Init] 'New file name
strDefpath = Application.ActiveWorkbook.Path 'Default path name
If IsEmpty(strDirname) Then Exit Sub
If IsEmpty(strFilename) Then Exit Sub
MkDir strDefpath & "\" & strDirname
strPathname = strDefpath & "\" & strDirname & "\" & strFilename 'create total string
.Copy
ActiveSheet.Shapes("Save").Visible = False
ActiveSheet.Shapes("SavePDF").Visible = True
ActiveWorkbook.SaveAs Filename:=strPathname & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathname & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
ActiveWorkbook.Close
End With
Range("A7").Value = Range("A7").Value + 1
Range("E1").Value = "=today()"
Range("A17:A50").Select
Selection.RowHeight = 15
Dim r1 As Range, r2 As Range, myMultiAreaRange As Range
Set r1 = Range("B1:C5")
Set r2 = Range("A13:A16")
Set myMultiAreaRange = Union(r1, r2)
myMultiAreaRange.Value = vbNullString
[COLOR=#ff0000] Dim tbl As ListObject[/COLOR]
[COLOR=#ff0000] Set tbl = ActiveSheet.ListObjects("Table1")[/COLOR]
[COLOR=#ff0000] [/COLOR]
[COLOR=#ff0000] With tbl.DataBodyRange[/COLOR]
[COLOR=#ff0000] If .Rows.Count > 4 Then[/COLOR]
[COLOR=#ff0000] .Offset(1, 0).Resize(.Rows.Count - 4, .Columns.Count).Rows.Delete[/COLOR]
[COLOR=#ff0000] End If[/COLOR]
[COLOR=#ff0000] End With[/COLOR]
Range("B1:C1").Select
If ThisWorkbook.Saved = False Then
ThisWorkbook.Save
End If
Application.ScreenUpdating = True
End Sub