Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-11-2023, 11:05 AM
puff puff is offline Possibility to copy and paste plain texts with image? Windows 7 64bit Possibility to copy and paste plain texts with image? Office 2013
Advanced Beginner
Possibility to copy and paste plain texts with image?
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Question Possibility to copy and paste plain texts with image?

I'm using adobe acrobat to convert a pdf into a word doc, but that doc has its own styles that if I directly copy and paste all the contents into my custom template, it'll flush out my custom styles in that template. As a compromise, I currently just copy and paste the texts as plain texts into my template and manually insert individual images into the doc. Is there a way to copy and paste texts as plain texts but with images such that the order of them is maintained through VBA code? My current code below can only copy and paste the images without changing my template, but it even sometimes also skips some images that I don't know why. I also attached images and files at the very end as examples for clarification.
Code:
Sub CopyPasteToTemplate()
    Dim InputDoc, OutputDoc As word.Document
    Dim paragraph As word.paragraph
    Dim shape As word.InlineShape
    
    Application.ScreenUpdating = False
    
    Set InputDoc = Application.ActiveDocument
    Set OutputDoc = Documents.Add(Template:="XXX\Templates\Normal.dotm")
    
    For Each paragraph In InputDoc.Paragraphs
        For Each shape In paragraph.Range.InlineShapes

            If shape.Type = wdInlineShapePicture Then  'Copy and paste the images without formating
                shape.Select
                Selection.Copy


                With OutputDoc.Content
                    .InsertParagraphAfter
                    .Paragraphs.Last.Range.Paste
                End With


            End If
        Next
        
'        paragraph.Range.Copy
'        With OutputDoc.Content
'            .InsertParagraphAfter
'            .Paragraphs.Last.Range.PasteSpecial wdFormatPlainText 'Sometimes gives an error 
'        End With
    Next
    
    OutputDoc.Activate
    
    Application.ScreenUpdating = True
End Sub
I would really appreciate any inputs!

Edit:
What I mean by "flushing the styles" is simply that before the pasting, my template and its instance doc have the styles as the left screenshot below, but after pasting in the contents, the styles section becomes the right screenshot below.

In the attached files, "acrobat export.docx" is the example docx output by acrobat, "direct copy paste.docx" is the resulting doc if I simply ctrl + A and ctrl + C to copy all contents in "acrobat export.docx" and paste in my custom dotm.

"manually processed.docx" is what I want the copy and paste into my template to look like. You can see that it's quite different from the previous 2 docx, including the page size/orientation and headers etc--these are the same as my dotm template. Currently, I can only make it by copying and pasting "acrobat export.docx" as plain texts into my template and manually inserting the images with a reference to the "acrobat export.docx" file.

Is there a way to iterate through all the objects (or paragraphs?) in the "acrobat export.docx" and judge...


- If text, copy and paste plain text into "code processed.docx"
- If bullet list, copy and paste plain text into "code processed.docx" with that "·" in the front. Same for the numbered list to preserve the numbering
- If image (no matter anchored or not), copy and paste the image as it is into "code processed.docx"
- If text box, extract the content, copy, and paste plain text into "code processed.docx"
- Ignore all other cases

I just want to maintain the order of texts and images in a cleaner way.
Attached Images
File Type: jpg original styles.jpg (17.5 KB, 15 views)
File Type: jpg styles after paste.jpg (18.6 KB, 15 views)
Attached Files
File Type: docx acrobat export.docx (199.7 KB, 4 views)
File Type: docx manually processed.docx (208.2 KB, 3 views)
File Type: docx direct copy paste.docx (220.7 KB, 2 views)

Last edited by puff; 01-11-2023 at 07:00 PM.
Reply With Quote
 

Tags
copy and paste, image insert, template document styles



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Between Two Headings/Texts Noob_VBA Word VBA 14 12-01-2021 12:28 PM
copy paste webp image from internet to word fails to appear DBenz Word 4 05-20-2020 06:49 PM
Need to copy texts from excel and paste in to the Notepad++ in between the particular tags ganesang Word VBA 2 08-27-2018 02:05 AM
Possibility to copy and paste plain texts with image? Keyboard shortcut to paste as plain unformatted text. Wyck Word 1 09-21-2016 03:49 PM
OneNote - Copy and paste image to the table MartinK OneNote 0 09-03-2013 05:08 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft