MrConfused10
12-31-2009, 06:05 AM
Hi all,
I'm hoping that someone will be able to help me. Firstly, I warn you I am very new to VBA and therefore what I have achieved so far is based on lots of time spend hunting around on the internet. :rotlaugh:
An explanation :
I am currently creating a series of documents that are for use in my business. The documents are reports that will be sent out to clients. In my industry legislation is changing all the time and therefore I need to ensure that I keep my documents up to date all the time. I have created a series of documents that link to a master excel spreadsheet, you simply update the spreadsheet and that in turn updates the documents templates.
In several of the reports I need to provide the user with the option to enter a predetermined block of text by selecting either option 1, 2 or 3. By making the selection the correct text is then entered.
I have built the following code that simply provides the user with the three options, in my example optISA1, 2 and 3. The selection points to a word document (that contains a table) copies the content, and then pastes the information in the active document.
The Problem :
The copy/paste seem to work ok, but the paste needs to be in a specific area of the original report. I have therefore bookmarked the section but it will not paste to the bookmark.
Could someone please look at this and correct me where I am going wrong, or offer some help. It will be greatly appreciated.
Dim strISA As String
If optISA1 = True Then strISA = Word.Documents.Open("F:\Neil H\Test 1.doc")
Word.ActiveDocument.Select
Word.Selection.Copy
If optISA2 = True Then strISA = Word.Documents.Open("F:\Neil H\Test 2.doc")
Word.ActiveDocument.Select
Word.Selection.Copy
If optISA3 = True Then strISA = Word.Documents.Open("F:\Neil H\Test 3.doc")
Word.ActiveDocument.Select
Word.Selection.Copy
Word.ActiveDocument.Close (False)
With ActiveDocument
Word.Selection.Paste
.Bookmarks("ISAType").Range.Text = strISA
End With
Application.ScreenUpdating = False
Many thanks
- Neil
:hi:
I'm hoping that someone will be able to help me. Firstly, I warn you I am very new to VBA and therefore what I have achieved so far is based on lots of time spend hunting around on the internet. :rotlaugh:
An explanation :
I am currently creating a series of documents that are for use in my business. The documents are reports that will be sent out to clients. In my industry legislation is changing all the time and therefore I need to ensure that I keep my documents up to date all the time. I have created a series of documents that link to a master excel spreadsheet, you simply update the spreadsheet and that in turn updates the documents templates.
In several of the reports I need to provide the user with the option to enter a predetermined block of text by selecting either option 1, 2 or 3. By making the selection the correct text is then entered.
I have built the following code that simply provides the user with the three options, in my example optISA1, 2 and 3. The selection points to a word document (that contains a table) copies the content, and then pastes the information in the active document.
The Problem :
The copy/paste seem to work ok, but the paste needs to be in a specific area of the original report. I have therefore bookmarked the section but it will not paste to the bookmark.
Could someone please look at this and correct me where I am going wrong, or offer some help. It will be greatly appreciated.
Dim strISA As String
If optISA1 = True Then strISA = Word.Documents.Open("F:\Neil H\Test 1.doc")
Word.ActiveDocument.Select
Word.Selection.Copy
If optISA2 = True Then strISA = Word.Documents.Open("F:\Neil H\Test 2.doc")
Word.ActiveDocument.Select
Word.Selection.Copy
If optISA3 = True Then strISA = Word.Documents.Open("F:\Neil H\Test 3.doc")
Word.ActiveDocument.Select
Word.Selection.Copy
Word.ActiveDocument.Close (False)
With ActiveDocument
Word.Selection.Paste
.Bookmarks("ISAType").Range.Text = strISA
End With
Application.ScreenUpdating = False
Many thanks
- Neil
:hi: