Solved

Macro code for autonumber insertion from Excel to Word?

Posted on 2007-03-28
4
540 Views
Last Modified: 2007-04-03
I am having trouble with a macro I am writing.   I am using a macro in excel to insert data critera based on answers from certain cell data.  The problem is that I want my data I am inserting in to the word document to use autonumber feature so that I can define my paragraphs with the autonumber following format "(1%)"

For some reason I cannot figure out the code so that it will insert my text using a progressive autonumber sequence.  Can anyone help me out here?
0
Comment
Question by:Spazalaz
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
TheTechGuysNYC earned 400 total points
ID: 18810499
Here is a good example to go by. The code below increments cell a2 by 1 when the spreadsheet is opened, beginning t 0001

The below code is an example that can be modified to fit your needs.

Private Sub Workbook_Open()

    Dim LOldVal As Integer
    Dim LNewVal As String

    'Retrieve current number
    LOldVal = Sheets("Sheet1").Range("A2").Value
    LNewVal = Format(LOldVal + 1, "0000")

    'Update to new number
    Sheets("Sheet1").Range("A2").Value = "'" & LNewVal

End Sub

Let me know if this helps!
0
 

Author Comment

by:Spazalaz
ID: 18811072
Not sure if that will work for me, I possibly was unclear with my request.  

I need to get the autonumber sequence to appear within the word document where I am inserting text based on specific critera and response inputs.

Thank you for your quick response so far though.
0
 

Author Comment

by:Spazalaz
ID: 18845179
I noticed I was very unclear, but the code you have presented may actually be useful.  It is close to being useful.

 What I need to figure out is is a line of code that will update that cell one number higher every time it is executed in the program.

Your code runs it so that it updates the cell once everytime it is opened, but what I want ist o be able to run it as a line everytime within a IF statement so that when a certain IF statement is executed it will automatically update the cell by one more number (allowing me to use that cell as an autonumber reference in my word document).  If that is unclear please let me know
0
 

Author Comment

by:Spazalaz
ID: 18845213
Actually your code works fine, thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now