Calling Integer Value from Excel spreadsheet

C

Chuck B.

I have a word template that upon opening initailizes a
form (frmTest) for finding and replacing all instances of
specified string. It also opens a text file in the same
directory "C:\Text\Text.txt", for performing the find &
replace functionality. I am trying to populate a text
box on the frmTest with a numberic value from an excel
spreadsheet (Counter.xls) in the same directory. This is
the replacing value. The spreadsheet is used for
incrementing the value everytime the replace coding is
initialized. Any suggestions on this would be greatly
appreciated.

Thanks,
Chuck
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Chuck,

I believe that it would be simpler to store/increment the number in an .ini
file by using System.PrivateProfileString. There's an example of how to do
that in the article “Creating sequentially numbered documents (such as
invoices)” at:

http://www.mvps.org/word/FAQs/MacrosVBA/NumberDocs.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
H

Helmut Weber

Hi Chuck,
if for some unknown reason it must to be Excel:
Dim oEx As Object
Set oEx = GetObject(, "Excel.application")
With oEx
With .ActiveWorkbook.Worksheets(1)
MsgBox .Cells(4, 4).Value 'present value
.Cells(4, 4).Value = .Cells(4, 4).Value + 1
MsgBox .Cells(4, 4).Value ' incremented value
End With
End With
It is assumed, that the appropriate Excel-File
is open.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 
C

Chuck

Thanks Helmut and Doug for your assistance. I did not
have to use excel for incrementing the number so I tried
Doug's suggestion for the AutoNew macro. I inserted the
Order bookmark in the template and the appropriate code.
I am getting an error at the following line of code that
the "Order variable is not defined".
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Chuck,

You will need to declare (DIM) the variable Order.

Dim Order as Long

Order = System.PrivateProfileString(etc.

We should go through and update all of the code in the articles on that site
to ensure that all variables are properly declared. You can get away
without declaring them if you have not specified Option Explicit.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
C

Chuck

Thanks, Doug. I really appreciate the help.
-----Original Message-----
Hi Chuck,

You will need to declare (DIM) the variable Order.

Dim Order as Long

Order = System.PrivateProfileString(etc.

We should go through and update all of the code in the articles on that site
to ensure that all variables are properly declared. You can get away
without declaring them if you have not specified Option Explicit.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top