![]() |
|
![]() |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
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 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 |
#2
|
||||
|
||||
![]()
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] |
#3
|
|||
|
|||
![]() Quote:
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. |
#4
|
||||
|
||||
![]()
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] |
#5
|
|||
|
|||
![]() Quote:
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.) |
#6
|
||||
|
||||
![]() Quote:
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] |
#7
|
|||
|
|||
![]()
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. |
#8
|
||||
|
||||
![]()
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] |
#9
|
|||
|
|||
![]()
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. |
#10
|
|||
|
|||
![]() Quote:
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 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. |
#11
|
|||
|
|||
![]()
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. |
![]() |
|
![]() |
||||
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 |
![]() |
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 |
![]() |
Agog | Word VBA | 4 | 05-03-2018 05:30 AM |
![]() |
heyjim | Drawing and Graphics | 1 | 08-07-2015 05:23 PM |