Solved

Macro code for autonumber insertion from Excel to Word?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

776 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