Thanks, Nigel.
However, using either
xlApp.Worksheets(3-Valuation Statement).Range(R6C3:R9C3).Select
or
xlApp.Worksheets("3-Valuation Statement").Range("R6C3:R9C3").Select
does not result in the range R6C3:R9C3 on Worksheet 3-Valuation Statement
being selected.
Using
xlApp.Worksheets(3-Valuation Statement).Activate
does result in the sheet being activated whereas
xlApp.Worksheets("3-Valuation Statement").Activate
does not. From that I surmise that the quote marks are not required when a
string variable is being supplied as in
bmname = Selection.Range.Bookmarks(1).Name 'This refers to a selection in a
Word document
If InStr(bmname, "Chart") = 0 Then
MsgBox "No chart selected."
Exit Sub
End If
var3 = ActiveDocument.Variables(bmname).Value
var3 = Mid(var3, 4, Len(var3) - 11)
var2 = Left(var3, InStr(var3, "!") - 1)
var3 = Mid(var3, InStr(var3, "!") + 1)
xlApp.Worksheets(var2).Activate
xlApp.Worksheets(var2).Range(var3).Select
xlApp.Visible = True
In the above code, the string supplied to var2 is the string "3-Valuation
Statement" without the quotes and the string supplied to var3 is "R6C3:R9C3"
also without the quotes.
Any other ideas?
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Nigel" <nigel-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If a named range exists then....
>
> Sheets("Sheet1").Range("myNamed Range").Select
>
> Or if a specific range
>
> Sheets("Sheet1").Range("A1:A2").Select
>
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
>
>
> "Doug Robbins - Word MVP" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Automating Excel from Word (2007), I have a variable var3 that contains a
>> reference of the form SheetName!R#C#:R#C#
>>
>> Using, and without Activating Excel
>>
>> xlApp.GoTo Reference:=var3
>> Set datarange = xlApp.Selection
>> datarange.Copy
>>
>> I can copy the required information to the clipboard so that it can be
>> pasted into Word.
>>
>> If however, I make Excel visible, the nearest that I can come to actually
>> selecting the range is to use
>>
>> xlApp.Visible = True
>> var2 = Left(var3, InStr(var3, "!") - 1)
>> xlApp.Worksheets(var2).Activate
>> xlApp.GoTo Reference:=var3
>>
>> and adding
>>
>> Set datarange = xlApp.Selection
>> datarange.Copy
>>
>> to the above, does not necessarily cause the required range of cells to
>> be copied (not that I really need to copy them in this situation,)
>>
>> Activating the Worksheet was necessary to get the Worksheet containing
>> the range to be made the active Worksheet.
>>
>> When Excel is visible, is there a way to get it to actually select a
>> specific range of cells?
>>
>> Thanks for any assistance.
>> --
>>
>> Doug Robbins - Word MVP
>>
>>
>