G
Gunnar Johansson
Hi,
I need to paste ranges and charts in to a new word file but don't know what
the user have.
From the enclosed code, I try to figure out how to make it flexible to
unknown >97 office users. I don't want to force any to go into VBE and
change objcet library etc. There must be a way - without access the
registry, that is to advanced for me - to paste charts and ranges to a new
word file.
Any suggestions?
/Regards
Sub ChartToDocument2()
'Here we use early binding and therefore we need to set
'a reference to MS Word Object Library x.x via the Tools | Reference...
'in the VB-editor.
Dim WDApp As Word.Application
Dim WDDoc As Word.Document
Set Word6 = CreateObject("Word.Basic")
With Word6
..AppRestore
..AppMaximize 1
..FileNewDefault
..InsertPara
End With
' Reference existing instance of Word
Set WDApp = GetObject(, "Word.Application.10")
' Reference active document
Set WDDoc = WDApp.ActiveDocument
' Reference active slide
For Each wWsht In ThisWorkbook.Worksheets
For Each sShape In wWsht.Shapes
sShape.CopyPicture
WDApp.Selection.PasteSpecial Link:=False, _
DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
Next sShape
Next wWsht
End Sub
Sub Excel_Range_Word()
'Here we use early binding which means that a
'reference must be set to MS Word Object Library x.x
'via Tools |Reference in the VB-editor
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnReport As Range
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim BMRange As Word.Range
Dim oShape As Word.InlineShape
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets("Sheet")
With wsSheet
Set rnReport = .Range("Rapport")
End With
I need to paste ranges and charts in to a new word file but don't know what
the user have.
From the enclosed code, I try to figure out how to make it flexible to
unknown >97 office users. I don't want to force any to go into VBE and
change objcet library etc. There must be a way - without access the
registry, that is to advanced for me - to paste charts and ranges to a new
word file.
Any suggestions?
/Regards
Sub ChartToDocument2()
'Here we use early binding and therefore we need to set
'a reference to MS Word Object Library x.x via the Tools | Reference...
'in the VB-editor.
Dim WDApp As Word.Application
Dim WDDoc As Word.Document
Set Word6 = CreateObject("Word.Basic")
With Word6
..AppRestore
..AppMaximize 1
..FileNewDefault
..InsertPara
End With
' Reference existing instance of Word
Set WDApp = GetObject(, "Word.Application.10")
' Reference active document
Set WDDoc = WDApp.ActiveDocument
' Reference active slide
For Each wWsht In ThisWorkbook.Worksheets
For Each sShape In wWsht.Shapes
sShape.CopyPicture
WDApp.Selection.PasteSpecial Link:=False, _
DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
Next sShape
Next wWsht
End Sub
Sub Excel_Range_Word()
'Here we use early binding which means that a
'reference must be set to MS Word Object Library x.x
'via Tools |Reference in the VB-editor
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnReport As Range
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim BMRange As Word.Range
Dim oShape As Word.InlineShape
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets("Sheet")
With wsSheet
Set rnReport = .Range("Rapport")
End With