Domenic wrote :
Unfortunately, that's an aspect of Excel I know nothing about. I tried
the Macro and I get an error message. I'm sure it's something I'm doing
wrong. The message is as follows:
Compile Error:
Only comments may appear after end sub, etc...
That comes from the way you did you "insertion" in fact within another macro
(but you couldn't know about it) Let's see it a bit further:
Here's what I did:
1) Opened my template invoice
Good start ;-)
2) Control clicked the sheet tab
3) Selected View Code
There would have been a better way.
4) Pasted the macro code between Private Sub Worksheet... and End Sub
That's where you did it wrong. That way you (I suppose) have two "End sub"
lines, which brings you the error message. Delete everything on that code
sheet if you haven't yet.
5) Amended the code to specify which cells contains InvoiceNumber and
CustomerNames (only these two fields for now until I can sort this out)
6) Amended the code to specify the correct path for my database file,
which I saved as Database.xls and placed on my desktop
That's right, but you won't necessarily save it on your desktop. Of course.
Open your Template Invoice.
With the "Tools menu" > "Macro" > "Visual Basic Editor" option (or the
"Option-F11" keyboard shortcut), open the VBE.
Add a module ("Insertion" > "Module") so you'll have a blank code sheet.
On this sheet, paste the macro from the previous message, and adapt it to
your needs.
"Option-F11" your way back to the usual Excel display. Save your Template.
Now you can run your macro with a "Option-F8" KB shortcut. If you want, you
can link your macro to a toolbar button: View" > "Toolbars" > "Customize",
then from the "Commands" pane, get the "custom button" from the "macro"
line, drag it to a toolbar. Control-click on it and Attach your macro to it.
From now on a click on this button will automatically launch your macro.
You can avoid the "flashing" of the display if you want, by inserting:
Application.ScreenUpdating = False
As a second line to the macro. Now it should read:
Sub SaveToDatabase()
Application.ScreenUpdating = False
InvoiceNumber = Range("A2") ' to be adapted
There are quite a few more possibilities to have it more sophisticated, but
let's already begin with this and let us know if you find your way out of
it...