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
Solved

Macro code for autonumber insertion from Excel to Word?

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

828 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