Invoice Code issues

WindowGuy

New Member
Joined
Sep 12, 2023
Messages
18
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Can not figure out the issue with this.
it saves the pdf but does not fill the records.

I followed a turtorial step by step and all worked until the last bit of code at the end....
Any help greatly appreciated.
FYI i am a beginner so may not understand references to items.

VBA Code:
Sub SaveInvAsExcel()

Dim invno As Long
Dim custname As String
Dim amt As Currency
Dim dt_issue As Date
Dim term As Byte
Dim path As String
Dim fname As String

invno = Range("C3")
custname = Range("B10")
amt = Range("I41")
dt_issue = Range("C5")
term = Range("C6")
path = "C:\Users\GeorgeDoucette\Desktop\THERMOTEK\Invoices\"
fname = invno & " - " & custname
Sheet27.Copy

Dim shp As Shape

For Each shp In ActiveSheet.Shapes
    shp.Delete
Next shp

With ActiveWorkbook
    .Sheets(1).Name = "Invoice"
    .SaveAs Filename:=path & fname, FileFormat:=51
    .Close
End With

Set nextrec = Sheet28.Range("A1048576").End(xlUp).Offset(1, 0)

nextrec = invno
nextrec.Offset(0, 1) = custname
nextrec.Offset(0, 2) = amt
nextrec.Offset(0, 3) = dt_issue
nextrec.Offset(0, 4) = dt_issue + term

Sheet28.Hyperlinks.Add anchor:=nextrec.Offset(0, 7), Address:=path & fname & ".xlsx"


End Sub
 

Attachments

  • excel issue.jpg
    excel issue.jpg
    204.5 KB · Views: 8

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Does it make any difference if you use Option Explicit to force declaration of all variables?
 
Upvote 0
Ok, in my opinion, Option Explicit should always be used because it forces declaration of all variables.
What you have would work if you had declared nextrec as a Range.
Do a quick google search of Option Explicit, it can be set to be included at the top of all code modules.

In the VBA environment, Tools > Options > Editor
check box for Require Variable Declaration
 
Last edited:
Upvote 0
Solution
Ok, in my opinion, Option Explicit should always be used because it forces declaration of all variables.
What you have would work if you had declared nextrec as a Range.
Do a quick google search of Option Explicit, it can be set to be included at the top of all code modules.

In the VBA environment, Tools > Options > Editor
check box for Require Variable Declaration
I dim it as range and boom it worked like a charm. Thank you very much. I couldn’t figure the option explicit thing out but dim as range worked.
 
Upvote 0
You're welcome.
I edited my last post (probably after you had already read it) and indicate where to set VBA to automatically add Option Explicit.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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