Solved

Macro code for autonumber insertion from Excel to Word?

Posted on 2007-03-28
4
586 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Make the most of your online learning experience.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

626 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