LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Can't Dim Range when Controlling Word from Excel

How do you distinguish between "ranges" in Excel vs. "ranges" in Word when
controlling Word using Excel VBA? Or is this necessary? I ask because I'm
getting a "Type Mismatch" error when trying to run VBA code in Excel that
controls a Word document.

I'm filling in a Word document form using Excel VBA and I'm trying to fill
in a field without deleting the bookmark. The code for how to do this in
Word VBA is provided at the following website
http://www.word.mvps.org/FAQs/Macros...AtBookmark.htm
but the problem I'm having is that the same code does not work in my Excel
VBA routine. Below is a portion of my Excel VBA routine.

I notice that when I type in my "Dim BMRange as R" that the editor comes up
with TWO "Range"s, and TWO of everything to chose from...leading me to
believe that the first one is an Excel Range and the second one a Word Range,
etc...

Dim Data As Range, cell As Range
....
Set wrdDoc = wrdApp.Documents.Open(WordTemplatesPath & FormType & ".dot")
With ActiveSheet
Set Data = ActiveSheet.AutoFilter.Range.Columns(5) 'bookmarks column
Set Data = Data.Offset(1, 0).Resize(Data.Rows.Count - 1, 1)
Set Data = Data.SpecialCells(xlVisible)
For Each cell In Data
UpdateBookmark cell.Value, Range(cell.Value)
Next
....
end sub

Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub

Any help would be appreciated.
Tony
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling MS Word from VBA Excel danp_db Excel Programming 2 October 31st 05 04:04 PM
controlling ms word from vba excel danp_db Excel Programming 0 October 29th 05 08:56 PM
Controlling Word from Excel Paul Haywood Excel Programming 3 June 30th 04 11:13 AM
Controlling Word from Excel tonesmcbutt Excel Programming 1 January 7th 04 09:21 PM


All times are GMT +1. The time now is 07:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"