Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

    I've got a problem when copying content from a HTML page and pasting it as HTML in my Word document.
    Word simply removes the spaces between the text and images.

    Steps to reproduce:

    1. create a simple HTML page with the following content:

    Code:
     where is the space between the image and this text?
    2. launch this page in IE, select the image and text, then paste it as HTML in Word

    You'll notice that the space between the image and the text has disapeared... I'm using Word 2007, but I've had this issue reported under Word 2003 and 2000 as well, so i think it affects all versions.

    Do you have any idea why Word is behaving like this? Any workaround?

    ------------

    I've been using the following workaround so far: it consists in looking for all the graphics that have just been pasted and adding a space after them. To do this, i've written the following macro:

    Code:
    Selection.Find.ClearFormatting
    	Selection.Find.Replacement.ClearFormatting
    	With Selection.Find
    		.Text = "^g"				' Find graphics
    		.Replacement.Text = "^& "   ' Replace the found graphics by itself plus an empty space
    		.Forward = True
    		.Wrap = wdFindStop
    		.Format = False
    		.MatchCase = False
    		.MatchWholeWord = False
    		.MatchWildcards = False
    		.MatchSoundsLike = False
    		.MatchAllWordForms = False
    	End With
    	Selection.Find.Execute Replace:=wdReplaceAll
    But.... this workaround raises a new issue with pasted images that are larger than the page... When this macro is executed and a space is added after this image, the text "Error!" gets inserted right before the graphic (see attached screenshot)... I can't even delete this text, or it'll remove the graphics with it.

    Any help would be welcomed
    Attached Images Attached Images

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Welcome to the Lounge!

    Try using a non-breaking space between the image and text.

    I can't reproduce the error with your macro in Word 2003.

  3. #3
    New Lounger
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heya,

    Thanks for your reply. Unfortunatly, I have no control on the HTML content that I get in input (I can't simply add a between text and images). Let's say I've got this HTML content copied in my clipboard, and I need to paste it as HTML, preserving the space between text and images.

    ------

    To reproduce the problem with my macro, create a web page with a very large image, like this one:

    Code:
     where is the space between the image and this text?
    Now copy and paste the content of this page in your document, select all the pasted content, and then execute the macro. You'll see the text "Error!" appear above the image.


    (You might wonder why i do need to execute this macro when i paste a very long image to my document, as it produces a line break after the image, causing the text to be displayed below it. The reason is that i must be able to copy/paste any kind of HTML content, with large or small images, and need to execute this macro to fix the problem with missing spaces. I've indeed no idea if some of the images are larger than my document.)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    OK, I see the problem now. The following appears to work better:

    Code:
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
      .ClearFormatting
      .Text = "^g" ' Find graphics
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      Do While .Execute
    	Selection.MoveRight Unit:=wdCharacter
    	Selection.TypeText " "
      Loop
    End With

  5. #5
    New Lounger
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Brilliant, this does the job perfectly!

    Thanks for your quick response Hans.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •