Can anyone explain to me how I fix this problem? I've asked the question before, but noone seems to understand the error. :/
My sub runs great in excel 2003, but in 2010 i get this error.
Can someone explain to me why vba doesn't recognize this as an OLE object?
What scaleheight is supposed to do, is making sure, that ALL the text copied into the word object is visible - which isn't the case if I set scaleheight to 1, but msoFalse.
You should be able to copy paste the code into a new sub.
Sub Embed_WordDocument_To_sheet()
Dim oWD As Document ' Word Document Object (Use Microsoft Word Reference)
Set ws = Worksheets.Add
Set wsFactark = Worksheets("Sheet1")
ws.Range("C3").Select
Set oOLEWd = ws.OLEObjects.Add( _
ClassType:="Word.Document", _
Width:=375)
oOLEWd.Name = "EmbeddedWordDoc"
oOLEWd.ShapeRange.LockAspectRatio = msoFalse
oOLEWd.Width = 375
oOLEWd.Height = 10 ' bliver ligegyldig når du har gjort det som står i nederste kommentar.
oOLEWd.Top = ws.Range("C3").Top + 2
oOLEWd.Left = ws.Range("C3").Left + 5
' PROBLEM - "The relativetooriginalsize argument applies only to a picture or an OLE object." !!! This goes through in 2003.. I need it to be msotrue because it sets the height of the word object to show all text. The text length is variable.
oOLEWd.ShapeRange.ScaleHeight 1, msoTrue
oOLEWd.Placement = xlFreeFloating
' Assign the OLE Object to Word Object
Set oWD = oOLEWd.Object
wsFactark.Cells(I + 4, 13).Copy
oWD.Paragraphs(oWD.Paragraphs.Count).Range.PasteAndFormat (wdFormatOriginalFormatting)
With oWD.PageSetup
.TopMargin = 0
.BottomMargin = 0
.LeftMargin = 0
.RightMargin = 0
.PageHeight = 1584 'max
.PageWidth = 1584
End With
oOLEWd.Activate
oOLEWd.Height = selection.Application.UsableHeight
oOLEWd.ShapeRange.Line.Visible = msoFalse
If oOLEWd.Height > 400 And oOLEWd.Height < 800 Then
ws.Range("B3").RowHeight = 400
ws.Range("B4").RowHeight = oOLEWd.Height - 400 + 20
ElseIf oOLEWd.Height > 800 And oOLEWd.Height < 1000 Then
ws.Range("B3").RowHeight = 400
ws.Range("B4").RowHeight = 200
ws.Range("B5").RowHeight = 200
ws.Range("B7").RowHeight = oOLEWd.Height - 800 + 20
ElseIf oOLEWd.Height > 1000 And oOLEWd.Height < 1200 Then
ws.Range("B3").RowHeight = 400
ws.Range("B4").RowHeight = 200
ws.Range("B5").RowHeight = 200
ws.Range("B6").RowHeight = 200
ws.Range("B7").RowHeight = 200
ws.Range("B9").RowHeight = oOLEWd.Height - 1000 + 20
Else
ws.Range("B3").RowHeight = oOLEWd.Height
ws.Range("B4:B11").RowHeight = 0
End If
ws.Range("B12").RowHeight = 10
Range("A1").Select
End Sub
Bookmarks