Solved

Macro code for autonumber insertion from Excel to Word?

Posted on 2007-03-28
4
525 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is about my first experience with programming Arduino.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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.

708 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

12 Experts available now in Live!

Get 1:1 Help Now