B
Ben K. Bullock
I know next to nothing about Visual Basic, but due to the extreme tedium and
frequent mistakes in typing in very repetitive sequences of
invoices/estimates/delivery notes involving the same numbers in several
places, I made the following function to make the documents automatically
using fields in a Word template. Basically I grabbed some code off the web
somewhere and messed around with it until it did more or less what I wanted.
There is also a pop up box where I can type in the numbers, and it is set to
open automatically when the template is clicked for a new document.
This works very well as far as it goes, and saves me several minutes of
fiddling and possible typing errors or forgetting to change numbers when
typing the complicated multipage repetitive invoices. However, in the
following, NoTaxCost should be UnitCost multiplied by NoOfPages, and
TotalCost should be that multiplied by 1.05 for the sales tax. So to be even
more lazy I would like this to calculate automatically for me and only have
to input two numbers, the unit cost and the number of pages I'm invoicing
for. It sounds simple enough, and I tried some things, as commented out
below, but they didn't work. What should I be doing?
Thanks for any assistance.
B. Bullock.
Private Sub CommandButton1_Click()
Dim UC As Integer
UC = Val(UnitCost.Text)
'NoTaxCost As Integer
'TaxCost As Integer
'TotalCost As Integer
'UnitCost := 2500
'NoTaxCost = UnitCost * NoOfPages
'TaxCost = NoTaxCost * 0.05
'TotalCost = NoTaxCost + TaxCost
With ActiveDocument
.Bookmarks("TaxCost").Range _
.InsertBefore TaxCost
.Bookmarks("CompanyName").Range _
.InsertBefore CompanyName
.Bookmarks("NoOfPages").Range _
.InsertBefore NoOfPages
.Bookmarks("NoTaxCost").Range _
.InsertBefore NoTaxCost
.Bookmarks("TotalCost").Range _
.InsertBefore TotalCost
.Bookmarks("UnitCost").Range _
.InsertBefore UnitCost
End With
'select all text
Selection.WholeStory
'update fields
Selection.Fields.Update
'move cursor to deselect
Selection.MoveUp Unit:=wdLine, Count:=1
UserForm1.Hide
End Sub
Private Sub TotalCost_Change()
End Sub
Private Sub UserForm_Click()
End Sub
frequent mistakes in typing in very repetitive sequences of
invoices/estimates/delivery notes involving the same numbers in several
places, I made the following function to make the documents automatically
using fields in a Word template. Basically I grabbed some code off the web
somewhere and messed around with it until it did more or less what I wanted.
There is also a pop up box where I can type in the numbers, and it is set to
open automatically when the template is clicked for a new document.
This works very well as far as it goes, and saves me several minutes of
fiddling and possible typing errors or forgetting to change numbers when
typing the complicated multipage repetitive invoices. However, in the
following, NoTaxCost should be UnitCost multiplied by NoOfPages, and
TotalCost should be that multiplied by 1.05 for the sales tax. So to be even
more lazy I would like this to calculate automatically for me and only have
to input two numbers, the unit cost and the number of pages I'm invoicing
for. It sounds simple enough, and I tried some things, as commented out
below, but they didn't work. What should I be doing?
Thanks for any assistance.
B. Bullock.
Private Sub CommandButton1_Click()
Dim UC As Integer
UC = Val(UnitCost.Text)
'NoTaxCost As Integer
'TaxCost As Integer
'TotalCost As Integer
'UnitCost := 2500
'NoTaxCost = UnitCost * NoOfPages
'TaxCost = NoTaxCost * 0.05
'TotalCost = NoTaxCost + TaxCost
With ActiveDocument
.Bookmarks("TaxCost").Range _
.InsertBefore TaxCost
.Bookmarks("CompanyName").Range _
.InsertBefore CompanyName
.Bookmarks("NoOfPages").Range _
.InsertBefore NoOfPages
.Bookmarks("NoTaxCost").Range _
.InsertBefore NoTaxCost
.Bookmarks("TotalCost").Range _
.InsertBefore TotalCost
.Bookmarks("UnitCost").Range _
.InsertBefore UnitCost
End With
'select all text
Selection.WholeStory
'update fields
Selection.Fields.Update
'move cursor to deselect
Selection.MoveUp Unit:=wdLine, Count:=1
UserForm1.Hide
End Sub
Private Sub TotalCost_Change()
End Sub
Private Sub UserForm_Click()
End Sub