![]() |
|
#1
|
|||
|
|||
|
Hi everyone, I am new guy here. Got some questions about vba automation
I am developing an automation script in Excel which will copy some excel rng as the picture and paste to the corresponding TextBox in Word. The second picture pasted will push the first pasted picture down as I expected, however, the third pasted picture will delete the previous 2 pictures and appears on the top, and the 4th pasted picture pushes down the 3rd pasted picture as expected again. What I want is to paste the four pictures to the textbox, however, after running the code, I only have the last 2 pictures in the textbox and the first 2 are deleted automatically. I don't know what is happening here. Thanks for your attention and help I have some setup like this: Code:
Dim appWord As Object, docWord As Object
On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then Set appWord = CreateObject("Word.Application")
appWord.Visible = True
Dim templatePath As String
templatePath = "C:\Users\JackMa\Desktop\WordTemplate.docx"
Set docWord = appWord.Documents.Open(templatePath, Visible:=True)
Dim WORD_BOX As Object
Dim EXCEL_RNG As Range
Code:
Set WORD_BOX = docWord.Shapes("MyTextBox")
Set EXCEL_RNG = ThisWorkbook.Sheets("Data").Range("AW387:BJ409")
EXCEL_RNG.CopyPicture xlPrinter, xlPicture
WORD_BOX.TextFrame.TextRange.Paste
With WORD_BOX.TextFrame.TextRange.InlineShapes(1)
.LockAspectRatio = msoFalse
.Width = WORD_BOX.Width - 1
.Height = 200
End With
Set EXCEL_RNG = ThisWorkbook.Sheets("Data").Range("AW310:BJ330")
EXCEL_RNG.CopyPicture xlPrinter, xlPicture
WORD_BOX.TextFrame.TextRange.Paste
With WORD_BOX.TextFrame.TextRange.InlineShapes(1)
.LockAspectRatio = msoFalse
.Width = WORD_BOX.Width - 1
.Height = 180
End With
Set EXCEL_RNG = ThisWorkbook.Sheets("Data").Range("AW233:BJ260")
EXCEL_RNG.CopyPicture xlPrinter, xlPicture
WORD_BOX.TextFrame.TextRange.Paste
With WORD_BOX.TextFrame.TextRange.InlineShapes(1)
.LockAspectRatio = msoFalse
.Width = WORD_BOX.Width - 1
.Height = 210
End With
Set EXCEL_RNG = ThisWorkbook.Sheets("Data").Range("AW156:BJ175")
EXCEL_RNG.CopyPicture xlPrinter, xlPicture
WORD_BOX.TextFrame.TextRange.Paste
With WORD_BOX.TextFrame.TextRange.InlineShapes(1)
.LockAspectRatio = msoFalse
.Width = WORD_BOX.Width - 1
.Height = 190
End With
|
| Tags |
| paste, textbox, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| wrapping text around a picture within a textbox | ketanco | Word | 3 | 04-06-2016 11:07 AM |
| Making an HTML Textbox Clickable (+ copy, paste, etc.) | Jonas.t1989 | Outlook | 0 | 08-25-2015 07:11 AM |
| Problem with copy paste | ayiru | Word | 4 | 03-30-2012 04:27 AM |
Copy/Paste from Paint to Word - There is a problem saving the file
|
one2three | Word | 1 | 10-26-2011 07:35 AM |
| Word Copy Paste Problem... | haxmania1 | Word | 1 | 07-30-2009 06:49 AM |