Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2022, 07:25 PM
zanodor zanodor is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Novice
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents
 
Join Date: Jun 2022
Posts: 17
zanodor is on a distinguished road
Default Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents

Hello all,

I am running a script that does all kinds of things (mostly find and replace to account for new syntax and styles) that ultimately saves my docx files in a folder into plain txt files which will no longer have a valid reference to all the images (jpg's, png's and gif's alas, but I could fix those by making them all jpg's to make things easy) but with the following two macros I would call after one another, I could point to the new files in a different (markdown) program (the references to images is
Code:
![[image.jpg]]
.
I couldn't make it work, alas. Probably a pro could merge the two macros into one as well.

Code:
Sub ReferenceMyImages()
    On Error Resume Next
    Dim pic As Word.InlineShapes
    Dim PicPath As String
For Each pic In ActiveDocument.InlineShapes
    With pic
    PicPath = Selection.ShapeRange(1).LinkFormat.SourceFullName
    PicPath = Selection.InlineShapes(1).LinkFormat.SourceFullName
    Selection.Collapse wdCollapseEnd
    Selection.TypeText vbCr & "<img src=" & Chr(34) & PicPath & Chr(34) & ">" & "Image Found Here"
    Selection.Collapse wdCollapseEnd
    End With
Next
End Sub
Code:
Sub ImageHere()
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "Image Found Here"
        .Replacement.Text = "![[image^&.jpg]]"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
With the second one I totally lost it, as I couldn't face trying to figure out how to put the brackets and all the code for WHAT I WANT: [each image in ActiveDocument matching the folder with the FileName (appended with) + files (in folder name) I got saved out by saving the docs to html beforehand.
So one filename is "Arad" and if that doc had any pics embedded in it, the corresponding folder's name will be "Arad_files". Each with different number of images (with different extensions, to boot) in those folders, if any.

I am now 85 percent done with the a migration project involving 14000 lexical entries mostly to do with religion history, archeoastronomy, astrotheology and etymology.


I was postponing migrating to a different platform for a long time. Working with hefty documents and having to rely on proximity/range search trying to find topics and bits of data previously catered to was no longer feasable. I had to find a more productive way and environment (Zettelkasten which works with markdown files and can be used a bit like a database).

If anybody is willing to help or willing to at least ask me to clarify even more what I want (it's 4.25 am where I live and want to call it a...whatever...), that would be much appreciated.

Regards,

Zan

Last edited by zanodor; 07-12-2022 at 09:58 AM. Reason: To wrap text up as code
Reply With Quote
  #2  
Old 07-11-2022, 07:51 PM
macropod's Avatar
macropod macropod is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your ReferenceMyImages sub only loops through InlineShapes. But you ignore what the loop is doing and use both:
• PicPath = Selection.ShapeRange(1).LinkFormat.SourceFullName (which is invalid for inlineshapes); and
• PicPath = Selection.InlineShapes(1).LinkFormat.SourceFullNam e (which is only valid for images inserted as links),
and both reference Selection, which isn't necessarily related to any image in the document - what might be selected when the macro is run might just be some text.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-12-2022, 10:18 AM
zanodor zanodor is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Novice
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents
 
Join Date: Jun 2022
Posts: 17
zanodor is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Your ReferenceMyImages sub only loops through InlineShapes. But you ignore what the loop is doing and use both:
• PicPath = Selection.ShapeRange(1).LinkFormat.SourceFullName (which is invalid for inlineshapes); and
• PicPath = Selection.InlineShapes(1).LinkFormat.SourceFullNam e (which is only valid for images inserted as links),
and both reference Selection, which isn't necessarily related to any image in the document - what might be selected when the macro is run might just be some text.
I borrowed those lines from a forum thread as you might have guessed. I had probably used your codes before in my migration project here and there and sometimes everything just worked (changing a bit of code to suit my needs). So this kind of hit or miss business is like this. Like trying to speak a foreign language with no grammar but some words picked up here and there. Although I have to say I am beginning to like VB/VBA. Reminds me of my BASIC days on C64. The last programming language I used was Pascal...

I am now thinking about inserting captions and looking around the net for changing those text parameters into hyperlinks which will be internal relative paths in the program I am going to be using.
I am also looking into how to go about using file and folder names and appending those. But everything is being made more difficult when you try to run macros on 14000 files and all files have different amount of images in them, if any.

I have a feeling I will have to resort to having just some placeholders or reminders to mark the positions of where the images used to be in the document.
Can you help me with that?

So I would need "For Each Image" (position) let's say a highlighted text or a bold green text to bring my attention to where I need to put some elbow grease in it when going through my documents. (With a macro I would change that bold green to something the markdown program will be able to interpret.)

In exchange I could tell you how "macro" and "meagre" are semanto-logically related. Even "Maker" as Creator.

Cheers,

Z.
Reply With Quote
  #4  
Old 07-12-2022, 01:40 PM
macropod's Avatar
macropod macropod is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

And from where would you get these captions? You can't get them from the images unless they were inserted as links. Embedded images contain no such data.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-12-2022, 03:19 PM
zanodor zanodor is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Novice
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents
 
Join Date: Jun 2022
Posts: 17
zanodor is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
And from where would you get these captions? You can't get them from the images unless they were inserted as links. Embedded images contain no such data.
Yes, I was aware of that. I looked into changing embedded pics into externally linked ones (there was a couple of forum threads dealing with that), but I thought now that I saved out all my images with HTML save (which gives you the formatted rich text plus the images in corresponding folders), I wouldn't need to make that change, only identify where the inline shapes are and mark those places just anyhow (a piece of bold text would do now that I know I will have gotten rid of all the bold by the time I get to this part of the drill).

See, I don't need the pictures, only reference their places within the next (usually in the text I make a comment; 'see attached image'; a cue I could use when I manually go about populating my files with images again), because once I save out as plain text, I say goodbye to all HTML formatting and attached images.
But before the save happens, I would need some "I was here" to help me with re-attaching the pics in the new environment. That's the whole idea. If you save out or render the text somewhere else as HTML and the images are gone or the respective paths have changed, at least you'd get an empty box inline to see this is where a picture used to be. Not with txt (which I needed to reformat for markdown).

(In the meantime, I am looking at other stuff that gives me a headache; I cannot believe automating a change of fonts is so difficult in footnotes; Recorded Macro/Selection method did it once and no more.)
Reply With Quote
  #6  
Old 07-12-2022, 03:27 PM
macropod's Avatar
macropod macropod is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by zanodor View Post
I cannot believe automating a change of fonts is so difficult in footnotes; Recorded Macro/Selection method did it once and no more.)
Unless you've used non-standard fonts in your footnotes, all you need to is modify the Footnote Text Style; you don't need to access even a single footnote.

You could also replace the images with code like:
Code:
Sub ReplacePics()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument.Range
  For i = .ShapeRange.Count To 1 Step -1
    With .ShapeRange(i)
      If .Type = msoPicture Then .ConvertToInlineShape
    End With
  Next
  For i = .InlineShapes.Count To 1 Step -1
    .InlineShapes(i).Range.Text = "![[image_" & i & "]]"
  Next
End With
Application.ScreenUpdating = False
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-12-2022, 05:13 PM
zanodor zanodor is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Novice
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents
 
Join Date: Jun 2022
Posts: 17
zanodor is on a distinguished road
Default

On the footnote: it is not the range-wide font style that is the problem. It is the fact that I want the bold chars unbolded and put the text withing double squared brackets, like so: individual bold text > [[^&]].
I can do it one by one using FIND IN but not in bulk method running the main overhaul macro.

On the code you've given me, give me a sec on that one as I am trying to somehow salvage not having to strip all the way do to raw txt after all (problem is my HTML had become very unclean using Word and Pages alternately over the last 6-7 years; different colour codes as well).
I'll get back to you.
Reply With Quote
  #8  
Old 07-12-2022, 05:44 PM
macropod's Avatar
macropod macropod is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Since I have no idea what your 'main overhaul macro' is, I can't comment on that. Regardless, what you want is as simple as:
Code:
Sub ReFormatFtNts()
Application.ScreenUpdating = False
Dim FtNt As Footnote
With ActiveDocument.Range
  For Each FtNt In .Footnotes
    With FtNt.Range
      .Font.Reset
      .InsertBefore "[["
      .InsertAfter "]]"
    End With
  Next
End With
Application.ScreenUpdating = False
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 07-12-2022, 06:38 PM
zanodor zanodor is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Novice
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents
 
Join Date: Jun 2022
Posts: 17
zanodor is on a distinguished road
Default Code

Ultimately I couldn't make it with HTML. There simply too many inconsistencies with the formatting. Sometimes within one longer word, there are three instances of switches off and on bold text. I don't remember formatting words to bold in three separate instances.

Last edited by zanodor; 07-12-2022 at 09:57 PM.
Reply With Quote
  #10  
Old 07-12-2022, 06:48 PM
zanodor zanodor is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Novice
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents
 
Join Date: Jun 2022
Posts: 17
zanodor is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Since I have no idea what your 'main overhaul macro' is, I can't comment on that. Regardless, what you want is as simple as:
Code:
Sub ReFormatFtNts()
Application.ScreenUpdating = False
Dim FtNt As Footnote
With ActiveDocument.Range
  For Each FtNt In .Footnotes
    With FtNt.Range
      .Font.Reset
      .InsertBefore "[["
      .InsertAfter "]]"
    End With
  Next
End With
Application.ScreenUpdating = False
End Sub
Just my idea of calling transforming my files. No biggie.

As for this code, how would you point the brackets around any bolded text. How would I go about selecting a range of bold?
I tried this before (hours ago), but no go:
Code:
With rg.Find
        .Font = .Bold = True
EDIT.
Anyway, in the meantime I just converted footnotes to endnotes (it retained formatting) and found'n'replaced on the bold texts.
Another one ticked off. I think I can go to bed now.

Thanks for everything, Paul

In Lak'ech

Last edited by zanodor; 07-12-2022 at 09:58 PM.
Reply With Quote
  #11  
Old 07-12-2022, 10:06 PM
zanodor zanodor is offline Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Windows 10 Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Office 2016
Novice
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents
 
Join Date: Jun 2022
Posts: 17
zanodor is on a distinguished road
Default One final thing

EDIT.
Deleted some lines here as I managed to work out the what I had in mind in a mere couple of minutes.
Of course another issue still stands: where did all the GIFs come from during my research? The problem is I cannot convert them (the PNGs are far less, thankfully) to the same number (001, 002, etc.) is it sometimes taken by a JPG that occupied an inline shape further up within the document. Anyway, I'll try to work it out outside of Word.

Cheers again

Z.

Last edited by zanodor; 07-13-2022 at 12:49 AM.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Insert Image(logo) into header for multiple Word Docs Axis Word VBA 4 02-09-2022 10:34 PM
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Changing footer image in Multiple word documents killabyte Word VBA 2 09-23-2020 05:49 AM
How to place an image placeholder that scales the image to the full frame size in a template Cube Word 5 07-05-2020 08:27 AM
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Adding Title Image to Multiple Documents. Agog Word VBA 4 05-03-2018 05:30 AM
Insert Image Reference in Each Deprecated Picture's Place in Multiple Documents Replace footer image in multiple Word documents heyjim Drawing and Graphics 1 08-07-2015 05:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:39 AM.


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