Word macro for replacing images with numbered index and moving the image to the end of document












0















I would like to create a Word macro to separate text and images. The macro should insert the text at first place and move the images inside the text to the end of the document and replace the image with an index showing the number of the image, starting from the first image to the last image. I would appreciate if someone could help with this.



I have looked in many sites and I have developed the following code. This code simply replaces any image in the document with a text which is a kind of index. For example, it replaces the first image with just simple index as “image1.jpg” and so on. But my problem is that I don’t want to just replace the image with a numbered text index. My goal is also to move for example the image 1 to the end of the document. This should happen for the second image in the document which is replacing the 2nd image with a numbered index and then moving the image to the end of the document (after the first image) and so on for other images. I guess that this code must be added with some other code to make this happen. if someone could help, it will help a lot for making web pages suitable for printing on papers using Microsoft word macro. because sometimes it is not always necessary to print the images in the document and the text alone would be enough.



Dim oILShp As InlineShape
Dim ILShpIndex As Integer
For Each oILShp In ActiveDocument.InlineShapes
ILShpIndex = ILShpIndex + 1
'insert text in place where InlineShape is located
ActiveDocument.Range(oILShp.Range.Start, oILShp.Range.End).Text = _
"[Image" & ILShpIndex & ".Jpg]"
'delete picture is not needed - it was simply replaced with text

Next









share|improve this question





























    0















    I would like to create a Word macro to separate text and images. The macro should insert the text at first place and move the images inside the text to the end of the document and replace the image with an index showing the number of the image, starting from the first image to the last image. I would appreciate if someone could help with this.



    I have looked in many sites and I have developed the following code. This code simply replaces any image in the document with a text which is a kind of index. For example, it replaces the first image with just simple index as “image1.jpg” and so on. But my problem is that I don’t want to just replace the image with a numbered text index. My goal is also to move for example the image 1 to the end of the document. This should happen for the second image in the document which is replacing the 2nd image with a numbered index and then moving the image to the end of the document (after the first image) and so on for other images. I guess that this code must be added with some other code to make this happen. if someone could help, it will help a lot for making web pages suitable for printing on papers using Microsoft word macro. because sometimes it is not always necessary to print the images in the document and the text alone would be enough.



    Dim oILShp As InlineShape
    Dim ILShpIndex As Integer
    For Each oILShp In ActiveDocument.InlineShapes
    ILShpIndex = ILShpIndex + 1
    'insert text in place where InlineShape is located
    ActiveDocument.Range(oILShp.Range.Start, oILShp.Range.End).Text = _
    "[Image" & ILShpIndex & ".Jpg]"
    'delete picture is not needed - it was simply replaced with text

    Next









    share|improve this question



























      0












      0








      0








      I would like to create a Word macro to separate text and images. The macro should insert the text at first place and move the images inside the text to the end of the document and replace the image with an index showing the number of the image, starting from the first image to the last image. I would appreciate if someone could help with this.



      I have looked in many sites and I have developed the following code. This code simply replaces any image in the document with a text which is a kind of index. For example, it replaces the first image with just simple index as “image1.jpg” and so on. But my problem is that I don’t want to just replace the image with a numbered text index. My goal is also to move for example the image 1 to the end of the document. This should happen for the second image in the document which is replacing the 2nd image with a numbered index and then moving the image to the end of the document (after the first image) and so on for other images. I guess that this code must be added with some other code to make this happen. if someone could help, it will help a lot for making web pages suitable for printing on papers using Microsoft word macro. because sometimes it is not always necessary to print the images in the document and the text alone would be enough.



      Dim oILShp As InlineShape
      Dim ILShpIndex As Integer
      For Each oILShp In ActiveDocument.InlineShapes
      ILShpIndex = ILShpIndex + 1
      'insert text in place where InlineShape is located
      ActiveDocument.Range(oILShp.Range.Start, oILShp.Range.End).Text = _
      "[Image" & ILShpIndex & ".Jpg]"
      'delete picture is not needed - it was simply replaced with text

      Next









      share|improve this question
















      I would like to create a Word macro to separate text and images. The macro should insert the text at first place and move the images inside the text to the end of the document and replace the image with an index showing the number of the image, starting from the first image to the last image. I would appreciate if someone could help with this.



      I have looked in many sites and I have developed the following code. This code simply replaces any image in the document with a text which is a kind of index. For example, it replaces the first image with just simple index as “image1.jpg” and so on. But my problem is that I don’t want to just replace the image with a numbered text index. My goal is also to move for example the image 1 to the end of the document. This should happen for the second image in the document which is replacing the 2nd image with a numbered index and then moving the image to the end of the document (after the first image) and so on for other images. I guess that this code must be added with some other code to make this happen. if someone could help, it will help a lot for making web pages suitable for printing on papers using Microsoft word macro. because sometimes it is not always necessary to print the images in the document and the text alone would be enough.



      Dim oILShp As InlineShape
      Dim ILShpIndex As Integer
      For Each oILShp In ActiveDocument.InlineShapes
      ILShpIndex = ILShpIndex + 1
      'insert text in place where InlineShape is located
      ActiveDocument.Range(oILShp.Range.Start, oILShp.Range.End).Text = _
      "[Image" & ILShpIndex & ".Jpg]"
      'delete picture is not needed - it was simply replaced with text

      Next






      microsoft-word images macros






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 28 '18 at 12:38









      harrymc

      256k14268568




      256k14268568










      asked Dec 28 '18 at 12:32









      VeronicaVeronica

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The following will loop through the inline shapes, add paragraphs to the end of the document and move the inline shapes there



          Dim oILShp As InlineShape
          Dim ILShpIndex As Long
          Dim oPara1 As Paragraph

          With ActiveDocument
          .Content.Paragraphs.Add
          For ILShpIndex = 1 To .InlineShapes.Count
          Set oILShp = .InlineShapes(1)
          Set oPara1 = .Content.Paragraphs.Add
          oPara1.Range.InsertParagraphAfter
          oPara1.Range.FormattedText = oILShp.Range.FormattedText
          .Range(oILShp.Range.Start, oILShp.Range.End).Text = "[Image" & ILShpIndex & ".Jpg]"
          Next ILShpIndex
          End With


          Note that since you need a counter anyways, you can use it to loop through the inlineShapes, using For Each oILShp In ActiveDocument.InlineShapes will cause you to loop infinitely through the shapes you would keep moving to the end of the document.






          share|improve this answer
























          • Thank you. it is working. with this, it will be easy to copy a website content including images and then pasting in word. Finally, I can choose whether to print the images or not since they are not inside the text.

            – Veronica
            Jan 2 at 12:12











          • If this answer works for you, you should mark it as correct -- we don't do this for free after all :)

            – cybernetic.nomad
            Jan 2 at 13:25











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1388434%2fword-macro-for-replacing-images-with-numbered-index-and-moving-the-image-to-the%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The following will loop through the inline shapes, add paragraphs to the end of the document and move the inline shapes there



          Dim oILShp As InlineShape
          Dim ILShpIndex As Long
          Dim oPara1 As Paragraph

          With ActiveDocument
          .Content.Paragraphs.Add
          For ILShpIndex = 1 To .InlineShapes.Count
          Set oILShp = .InlineShapes(1)
          Set oPara1 = .Content.Paragraphs.Add
          oPara1.Range.InsertParagraphAfter
          oPara1.Range.FormattedText = oILShp.Range.FormattedText
          .Range(oILShp.Range.Start, oILShp.Range.End).Text = "[Image" & ILShpIndex & ".Jpg]"
          Next ILShpIndex
          End With


          Note that since you need a counter anyways, you can use it to loop through the inlineShapes, using For Each oILShp In ActiveDocument.InlineShapes will cause you to loop infinitely through the shapes you would keep moving to the end of the document.






          share|improve this answer
























          • Thank you. it is working. with this, it will be easy to copy a website content including images and then pasting in word. Finally, I can choose whether to print the images or not since they are not inside the text.

            – Veronica
            Jan 2 at 12:12











          • If this answer works for you, you should mark it as correct -- we don't do this for free after all :)

            – cybernetic.nomad
            Jan 2 at 13:25
















          0














          The following will loop through the inline shapes, add paragraphs to the end of the document and move the inline shapes there



          Dim oILShp As InlineShape
          Dim ILShpIndex As Long
          Dim oPara1 As Paragraph

          With ActiveDocument
          .Content.Paragraphs.Add
          For ILShpIndex = 1 To .InlineShapes.Count
          Set oILShp = .InlineShapes(1)
          Set oPara1 = .Content.Paragraphs.Add
          oPara1.Range.InsertParagraphAfter
          oPara1.Range.FormattedText = oILShp.Range.FormattedText
          .Range(oILShp.Range.Start, oILShp.Range.End).Text = "[Image" & ILShpIndex & ".Jpg]"
          Next ILShpIndex
          End With


          Note that since you need a counter anyways, you can use it to loop through the inlineShapes, using For Each oILShp In ActiveDocument.InlineShapes will cause you to loop infinitely through the shapes you would keep moving to the end of the document.






          share|improve this answer
























          • Thank you. it is working. with this, it will be easy to copy a website content including images and then pasting in word. Finally, I can choose whether to print the images or not since they are not inside the text.

            – Veronica
            Jan 2 at 12:12











          • If this answer works for you, you should mark it as correct -- we don't do this for free after all :)

            – cybernetic.nomad
            Jan 2 at 13:25














          0












          0








          0







          The following will loop through the inline shapes, add paragraphs to the end of the document and move the inline shapes there



          Dim oILShp As InlineShape
          Dim ILShpIndex As Long
          Dim oPara1 As Paragraph

          With ActiveDocument
          .Content.Paragraphs.Add
          For ILShpIndex = 1 To .InlineShapes.Count
          Set oILShp = .InlineShapes(1)
          Set oPara1 = .Content.Paragraphs.Add
          oPara1.Range.InsertParagraphAfter
          oPara1.Range.FormattedText = oILShp.Range.FormattedText
          .Range(oILShp.Range.Start, oILShp.Range.End).Text = "[Image" & ILShpIndex & ".Jpg]"
          Next ILShpIndex
          End With


          Note that since you need a counter anyways, you can use it to loop through the inlineShapes, using For Each oILShp In ActiveDocument.InlineShapes will cause you to loop infinitely through the shapes you would keep moving to the end of the document.






          share|improve this answer













          The following will loop through the inline shapes, add paragraphs to the end of the document and move the inline shapes there



          Dim oILShp As InlineShape
          Dim ILShpIndex As Long
          Dim oPara1 As Paragraph

          With ActiveDocument
          .Content.Paragraphs.Add
          For ILShpIndex = 1 To .InlineShapes.Count
          Set oILShp = .InlineShapes(1)
          Set oPara1 = .Content.Paragraphs.Add
          oPara1.Range.InsertParagraphAfter
          oPara1.Range.FormattedText = oILShp.Range.FormattedText
          .Range(oILShp.Range.Start, oILShp.Range.End).Text = "[Image" & ILShpIndex & ".Jpg]"
          Next ILShpIndex
          End With


          Note that since you need a counter anyways, you can use it to loop through the inlineShapes, using For Each oILShp In ActiveDocument.InlineShapes will cause you to loop infinitely through the shapes you would keep moving to the end of the document.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '18 at 20:01









          cybernetic.nomadcybernetic.nomad

          1,455112




          1,455112













          • Thank you. it is working. with this, it will be easy to copy a website content including images and then pasting in word. Finally, I can choose whether to print the images or not since they are not inside the text.

            – Veronica
            Jan 2 at 12:12











          • If this answer works for you, you should mark it as correct -- we don't do this for free after all :)

            – cybernetic.nomad
            Jan 2 at 13:25



















          • Thank you. it is working. with this, it will be easy to copy a website content including images and then pasting in word. Finally, I can choose whether to print the images or not since they are not inside the text.

            – Veronica
            Jan 2 at 12:12











          • If this answer works for you, you should mark it as correct -- we don't do this for free after all :)

            – cybernetic.nomad
            Jan 2 at 13:25

















          Thank you. it is working. with this, it will be easy to copy a website content including images and then pasting in word. Finally, I can choose whether to print the images or not since they are not inside the text.

          – Veronica
          Jan 2 at 12:12





          Thank you. it is working. with this, it will be easy to copy a website content including images and then pasting in word. Finally, I can choose whether to print the images or not since they are not inside the text.

          – Veronica
          Jan 2 at 12:12













          If this answer works for you, you should mark it as correct -- we don't do this for free after all :)

          – cybernetic.nomad
          Jan 2 at 13:25





          If this answer works for you, you should mark it as correct -- we don't do this for free after all :)

          – cybernetic.nomad
          Jan 2 at 13:25


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1388434%2fword-macro-for-replacing-images-with-numbered-index-and-moving-the-image-to-the%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Plaza Victoria

          In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

          How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...