h1

Word: Make some specific text bold

September 14, 2018

As most people would know, you can apply bold formatting in Word using Ctrl+b or the Bold icon on the Home table on the Ribbon.

But what if you want more? What if you have some specific text scattered throughout your document that you want to make bold in one action? This was the issue Colin faced. In a comment on one of my other blog posts, Colin asked if there was a way to apply bold a set of characters that all started with the same code, but had different numbers after that code (e.g. like product codes). In his example, he had a lot of instances of VA-001, VA-002, etc. with the last three digits being different each time. He’d tried the method I’d documented in my earlier post, but he could only bold part of the code, not all of it.

As with any find and replace, once you identify the pattern, it’s easy enough to test various ways of finding a match and then applying the change to it. I figured out two methods—both using wildcards. The first method assumes there are only ever three characters (not, 1, 2, 4, etc.) after the VA- part, while the second applies to any length of the ‘word’ after VA-.

For both methods, open the Find and Replace window (Ctrl+h), click More, then check the option for Use wildcards.

Method 1: Only three characters

  1. In the Find field, type: (VA-)(???)
  2. In the Replace with field, type: \1\2
  3. With your cursor still in the Replace with field, click Format, then Font, then select Bold. You should see Font: Bold directly below the Replace with field (see screenshot).
  4. Click Replace a few times to make sure the find/replace is doing what you expect it to. Once you are satisfied, you can click Replace All.

Notes:

  • In the Find, the code is separated into two parts, both surrounded by parentheses—the VA- part, which is a constant in what Colin had, and three question marks (???). A single question mark represents any single character, so by typing three question marks, you’re asking Word to look for ANY three characters (letters and/or numbers) after the VA- part. If you only had two characters, then you’d type two question marks; if you had 4, then you’d type four, etc.
  • In the Replace, you’re replacing what was found in both parts with itself. In other words, you’re not changing anything. What you are doing in the Replace, though, is specifying that what you find and replace with itself is now bold (step 3).

Method 2: Any number of characters

  1. In the Find field, type: (VA-)(*>)
  2. In the Replace with field, type: \1\2
  3. With your cursor still in the Replace with field, click Format, then Font, then select Bold. You should see Font: Bold directly below the Replace with field (see screenshot).
  4. Click Replace a few times to make sure the find/replace is doing what you expect it to. Once you are satisfied, you can click Replace All.

Notes:

  • In the Find, the code is separated into two parts, both surrounded by parentheses—the VA- part, which is a constant in what Colin had, and an asterisk followed by a right chevron arrow. The asterisk represents any number of characters from one to infinity. Because a ‘character’ in Word could be a space, you don’t want it to find EVERY character after the VA- part—you’d get the whole document! So you add the > to tell Word to stop at the end of the ‘word’ it finds. In other words, it will stop at any character that typically follows a set of adjacent characters (a ‘word’), such as a space, period, comma, colon, semicolon, etc.
  • In the Replace, you’re replacing what was found in both parts with itself. In other words, you’re not changing anything. What you are doing in the Replace, though, is specifying that what you find and replace with itself is now bold (step 3).

[Links lat checked September 2018]

h1

Word: Macro to convert from one style to another

September 11, 2018

I should have hunted this out years ago. My main client has a habit of changing templates every couple of years, which means the old docs have to go onto the current template when they get revised. It’s a pain and involves quite a few steps (and up to several hours) per document. I still have to do the cover page and headers/footers manually, and all the landscape/portrait sections, but now I’ve got a way to convert styles in the older template to differently named styles in the newer template. For styles with the same name, no such conversion is necessary, but when the old style is called ‘Table Bullet 1’ and the new one is called ‘Table Bullet’ you have to either reapply the correct style everywhere it is used (ugh!), do a global find and replace for the style, or do a ‘select all’ for the style and then click the new style to apply it.

Some caveats:

  • Test first. Test on a COPY of the old document before doing it on the original copy, and any other documents in the set.
  • Make sure you’ve applied the new template to the old document so that the new styles are available in the document. (or, use the Organizer to copy styles across from the old template to the new [longer, slower method]).
  • Make a list of the old styles and the matching, but differently named, new styles—make sure you write down the style names EXACTLY (including any hyphens in the style name) otherwise this macro won’t work.
  • This macro runs a find and replace and replaces ALL. Test first.

Acknowledgements: I modified the macro written by Christina and available from here: https://stackoverflow.com/questions/29953322/changing-styles-in-word-using-vba to suit my client’s situation.

In my modified macro below, several styles used in tables had name changes, as did one for the appendix headings. You can add more for your circumstances—just make sure you add a new ‘Set’ line with a unique name, call that name in a separate ‘With’ statement, and make sure you add that name to the ‘Dim’ statement at the top of the macro.

If you want to use/modify this macro, copy/paste the code below–some of it runs off the page, so if you retype the code you may miss some critical command. Then modify the Set names (if required) and the style names in the double quotes.

Sub FNR_Styles()

' Converts old table and Appendix styles to new using find and replace
' Rhonda Bracey, 11 Sept 2018 (modified from https://stackoverflow.com/questions/29953322/changing-styles-in-word-using-vba [Christina])

Dim objDoc As Document
Dim table1 As Style, table2 As Style, table3 As Style, table4 As Style, app1 As Style

Set objDoc = ActiveDocument
' This code does *NOT* protect against the possibility that these styles don't
' appear in the document. That's probably not a concern with built-in styles,
' but be aware of that if you want to expand upon this for other uses.
' Set up as many of these as you need, giving each a unique name.
' The style name in the quote marks is the NEW style name.
' Make sure you add the name to the second Dim row at the top of the macro as well.

Set table1 = ActiveDocument.Styles("Table Text")
Set table2 = ActiveDocument.Styles("Table Bullet")
Set table3 = ActiveDocument.Styles("Table Heading White")
Set table4 = ActiveDocument.Styles("Table Text Number")
Set app1 = ActiveDocument.Styles("Appendix Heading")

' Searches the entire document (but not foot/endnotes, headers, or footers)
' for the old style and replaces it with the new style.

With objDoc.Content.Find
    .ClearFormatting
    .Style = "Table Text - Left"
    ' The style in the quote marks is the OLD style name
    With .Replacement
    .ClearFormatting
    .Style = table1
    End With
    ' Below is the Replace All command.
    ' Could change this to Replace:=wdReplaceOne to replace one only
   
    .Execute Wrap:=wdFindContinue, Format:=True, Replace:=wdReplaceAll
End With

With objDoc.Content.Find
    .ClearFormatting
    .Style = "Table Bullet 1"
    With .Replacement
    .ClearFormatting
    .Style = table2
    End With
    .Execute Wrap:=wdFindContinue, Format:=True, Replace:=wdReplaceAll
End With
With objDoc.Content.Find
    .ClearFormatting
    .Style = "Table Head - Center"
    With .Replacement
    .ClearFormatting
    .Style = table3
    End With
    .Execute Wrap:=wdFindContinue, Format:=True, Replace:=wdReplaceAll
End With
With objDoc.Content.Find
    .ClearFormatting
    .Style = "Table Text - Number"
    With .Replacement
    .ClearFormatting
    .Style = table4
    End With
    .Execute Wrap:=wdFindContinue, Format:=True, Replace:=wdReplaceAll
End With
With objDoc.Content.Find
    .ClearFormatting
    .Style = "App H1"
    With .Replacement
    .ClearFormatting
    .Style = app1
    End With
    .Execute Wrap:=wdFindContinue, Format:=True, Replace:=wdReplaceAll
 End With

End Sub

 

h1

Google: Identify a song

September 7, 2018

I don’t have a Google Home or Assistant device, nor do I have any music apps or subscribe to any music streaming services, but I do have an Android phone and tablet, and on them I can get Google to listen to a piece of music and identify the song, artist, when released etc. Pretty cool! (NOTE: I don’t own an ‘i’ anything, so I don’t know if this ‘listen to music’ trick works on iPhones, iPads etc. too — could one of my readers test and see if it works on an ‘i’ device? Just let me know in the comments.)

When do I use this cool feature the most? Nearly always when I’m watching TV and a piece of music comes on in the background that sounds like I might want to hear more, or to settle an argument a civilised discussion over what song and artist it is.

Here’s how you get Google to perform this wizardry (for free) and tell you what music is playing:

  1. First, make sure some music is playing, and that it’s loud enough for Google to hear.
  2. On the home screen of your device, tap the microphone icon in the Google quick search bar.
  3. Google starts listening for a voice command.

  4. If it doesn’t hear one, it suggests ‘What’s this song?’
  5. Tap on the musical note icon.
  6. Google starts listening… This can take several seconds, so be patient.
  7. If Google identifies the song, it displays the details about it in a search results screen.
  8. Now, collect the money you’re owed by your companion for the bet you made on which song/which artist. Sorry, that shouldn’t be there…
h1

Google Docs: Speech to text function

September 5, 2018

If you have a Gmail address, a YouTube account, or are signed up to anything ‘Google’, then you have access to Google Docs. And if you have access to Google Docs, you have access to free—and surprisingly accurate—speech to text transcription. I rarely use Google Docs, and I only learned about this feature today. I spent a few minutes testing it, and after I’d checked the Help on how to add punctuation, the end result was very good. It’s worth a try, and is heaps cheaper than many other transcription services and software.

Prerequisites:

  • A working microphone linked into your computer/device (often comes with your headset or device, or may be separate) and turned on
  • Logged into Google Docs on your browser with one of your Google accounts (e.g. Gmail).

Here’s how to transcribe speech into text using Google Docs (these instructions and screenshots are for the Chrome browser on a Windows 7 PC, but other browsers and operating systems should work similarly):

  1. Open a new Google Docs document.
  2. Go to Tools > Voice Typing.
  3. A microphone icon is added to the left of the document. Click the drop-down arrow at the top of the microphone icon and select your language. As you can see from the screenshot, I chose English (Australia).
  4. Click the gray microphone icon when you’re ready to speak or read your text—the microphone icon will turn red, indicating that you can begin speaking.
  5. As you are speaking, don’t forget to add in the punctuation—say ‘period’ at the end of each sentence and ‘comma’ where you want a comma. Other accepted commands are ‘exclamation point’, ‘question mark’, ‘new line’, and ‘new paragraph’.
  6. When you have finished, click the red microphone icon again—it will change back to gray.
  7. Check the text created, and edit as required. In my testing (reading software information, so slightly technical content), I only had to make a few very minor edits.

I was very impressed. But then, I think Google has really excelled with voice recognition in the past few years (think Google Home, Alexa, and the brilliant ‘listen to music‘ option that tells you what song is playing and who’s performing it—we use this a lot when there’s interesting background music in a TV show and we want to follow up the artist and performance; I might write a blog post on it tomorrow…).

 

h1

Some people’s words just make you smile

August 30, 2018

I got this delightful email from a reader in the UK—I like the way she writes :-)

I’ve only just discovered your lovely, informative WordPress blog, courtesy of an extremely boring temp job where I thankfully and gleefully had internet access. I might not have made it through those days without you. I love the techy stuff anyway, but I was like a dog with two tails when I discovered the ‘freewheeling through the ribbon with the mouse scroll’, and the ‘shakey shakey’ technique to drop the other windows. Strangers who passed me in the street on the way home now know of these two joys.

Glad I could help, Tessa!

h1

Word: Extract file names of images

August 30, 2018

In my post yesterday, I showed three ways of extracting file name information if it was entered in the Alt Text properties of the image. However, file names/file paths don’t automatically populate the Alt Text description field, except under some circumstances. In my testing:

  • if I dragged a saved image from Windows Explorer into Word 2010, the file path and name was added to the Alt Text description field automatically (NOTE: Dragging from Explorer did NOT add the file path/name information in Word 2016 [and possibly in Word 2013]! It seems Microsoft changed this function after Word 2010 for at least one of these reasons: large corporate clients didn’t want file paths visible to readers with the knowledge to find out what they were, or, putting the file path in Alt Text actually went against accessibility guidelines, because a screen reader would read the file path NOT a considered description of what the image was about.)
  • if I dragged a saved image from SnagIt Editor, the file path and name was added to the Alt Text description field automatically
  • if I clicked Insert > Picture in Word, selected an image, then clicked Insert, none of the file information was carried across
  • if I clicked Insert > Picture in Word, selected an image, then clicked the drop-down arrow next to Insert and then selected Insert and Link, the file path/name information is stored in Word, but NOT under Alt Text—you can only find it by going to File > Info, then clicking Edit Links to Files (bottom right of that Info window), then scrolling through the list of links to find those for images. Click the item in the list and the file path/name is displayed in the Source information section. You can’t select it to copy it.

An alternative way to find these file names (whether detailed in Alt Text or not) is to save the Word document as an XML file, then open the XML file in an HTML editing program (you can use a program like Notepad, but you have to find them one at a time for each image file extension [e.g. .gif, .jpg, .jpeg, .png, .emf, .svg, .bmp, .tif, .tiff, etc.]). Ignore any found with paths/names like /media/image1.png etc. as these are the automatically created image files when you saved as XML—they are not the original final names. When you find a legitimate file path/name, copy it to another document. Yes, this is tedious, and there is a marginally quicker way if you have an HTML editing program installed and have a lot of image file names to deal with.

NOTE: You will never get the file name/path for anything inserted using Insert > Picture without linking.

I had Microsoft Expression Web installed on my computer so I used that—it allows you to search for all instances of a term (in my case, a file extension) and lists them in a Results pane. From there, you select them all, then copy the list and paste it into Excel. Once in Excel, you can delete the columns you don’t need and do find/replace to clean up the XML coding you don’t want. Hopefully, you’ll get enough file names to make this a worthwhile exercise.

Here are the steps I used with Expression Web:

  1. Open a new Excel document.
  2. Open the Word document, then save it as an XML file (File > Save As, select Word XML document (*.xml) as the file type). Close the Word document.
  3. Go to (Windows) Explorer, right-click on the XML file you saved in Step 2, then choose the program to open it—in my case, I opened it with Microsoft Expression Web 2.0, and the rest of these instructions are for that program.
  4. Go to Edit > Find, then enter the search term for an image format file extension (the most common ones are .gif, .jpg, .jpeg, .png, .emf, .svg, .bmp, .tif, and .tiff). You can make this quicker by entering .jp to find both jpg and jpeg formats, or .ti to find both .tif and .tiff formats.
  5. Click Find All.
  6. The Results list below the main window shows all lines where the search term was found. Click in the Results list, then press Ctrl+a to select all results.
  7. Right-click on the selected results, then choose Copy Results (Note: Ctrl+c will NOT copy them).
  8. Go to your blank Excel document, and paste the copied results into Excel.
  9. Repeat Steps 4 to 8 for all the other image file formats.
  10. When you have finished finding them all and putting them into the Excel document, save the Excel file.
  11. Now it’s time to clean up the Excel file:
    • delete any columns you don’t need (I only needed the Matched Text column, so I deleted the others)
    • delete any rows you don’t need (those with /word/media/image1.png or /media/image1.png in them—these are the auto generated file names created when you save the Word document as XML)
    • delete any duplicates
    • if you see patterns in the XML code, do several find/replace runs on the file to get rid of the unwanted XML code (e.g. find <wp:cNvGraphicFramePr><a:graphicFrameLocks noChangeAspect=”1″… and replace with nothing)
    • manually delete any remaining XML code that you can’t delete easily with find/replace
  12. Once you’ve cleaned it up, your Excel file should list all the found file paths/names. Sort the list alphabetically so you can identify and delete any further duplicates. (Note: Some images may be listed twice — just the file name and another with the full file path.)

[Links last checked August 2018]

h1

Word: Extract Alt Text from images

August 29, 2018

Mary, one of this blog’s regular readers and donors, emailed me with a problem:

I want to manage all the image files in my Word 2007 docs and RoboHelp online help projects. Many times the image from the Word doc is used in the online help. Also an image can be used in more than one doc. So when an image is edited/updated it would be useful to know where it has been used. For that I need to know the image file name. Is there any way to find the original file name of the image? I know the ‘trick’ of saving as a web page to produce a media folder but the images are (unhelpfully) renamed as 1, 2, 3 and so on.

Hmmm… A curly one, for sure. Like Mary, I’d found that the images saved when you save to XML or HTML were unhelpfully named. I even checked the image properties to find if any of the information about the original image is preserved in the ‘save as’ file—it isn’t. So I went back to my test document in Word to look at the image properties and discovered something I hadn’t noticed before. In my test document, there was an Alt Text description for some of the images, AND, helpfully, that description often included the file name and sometimes the full file path on the network (see the follow-up post to this one for information on the method to use to always get the file name/path added automatically to the Alt Text description). This was a big bonus! Knowing that this information is stored with the image in the Word document means there has to be a way to extract it, right?

Well, yes there is, but all extraction methods below assume that the images have an Alt Text description associated with them. If you don’t have any Alt Text, there’s nothing to extract. For new documents, I would suggest that you start adding Alt Text to your images from now on (good practice for accessibility reasons anyway), and if you ever need the name of the original file, put that in the Alt Text description (along with the file path, if that’s unlikely to change). You can do this manually, or, if you use the right method, Word can add it automatically for you. For older documents, you’d have to find the original file and then add the Alt Text—this might not be practical, especially if you have a lot of documents with a lot of images. For information on how to add Alt Text, see: https://www.itsupportguides.com/knowledge-base/office-2016/word-2016-how-to-add-alt-text-to-images/

Now as to the solutions I looked at and that worked, from low tech to high tech. These solutions range from manually finding the Alt Text description (in the HTML file), to running a macro to display the Alt Text in a message box for each image, to running a macro that extracts all the Alt Text from a selected file and puts it into a new Word document. Choose the one that most suits your purposes.

I must thank John SR Wilson and Jay Freedman whose generosity in helping those on the Microsoft forums is amazing. I used their macros (with very minor adaptations) to achieve what Mary wanted.

Find the Alt Text description in the HTML file

Use this method if you only have a few images with Alt Text.

  1. Open the Word document.
  2. Save as an HTML file.
  3. Open the saved HTML file in a text editor (e.g. NotePad).
  4. Search for alt=.
  5. If the alt= information is a file name/path, copy that into another document so you have a list of them.

Macro to display the Alt Text for each image

This macro from John SR Wilson runs through your document and pops up a message box for each image it finds. The message box displays the Alt Text if there is any, otherwise it tells you that no Alt Text was found for that image. Keep clicking OK until the end (you can’t cancel). NOTE: The code runs off the screen, so copy/paste all lines—don’t try to type them out.

Sub getAltText()
'
' getAltText Macro
' Identifies if Alt Text is associated with an image or not. If so, displays the Alt Text; if not, says No Alt Text
' from: John SR Wilson, at https://answers.microsoft.com/en-us/office/forum/office_2010-customize/how-do-i-access-alt-text-for-pictures-with-vba/b3d196a6-b31f-4f28-90bb-be4f7e73958c?db=5

Dim oshp As InlineShape
For Each oshp In ActiveDocument.InlineShapes
oshp.Select
If oshp.AlternativeText <> "" Then
MsgBox "Alt Text is " & oshp.AlternativeText
Else
MsgBox "No Alt Text"
End If
Next

End Sub

Macro to extract the Alt Text from each image and put it into a separate document

This macro from Jay Freedman first asks you to select the file you want to run the macro on (it doesn’t have to be the currently open file), then a few seconds later, it asks where you want to save the new document containing all the Alt Text. NOTE: The code runs off the screen, so copy/paste all lines—don’t try to type them out.

Sub ExportAltText()
' Exports all Alt Text for inline images in a selected document into a separate file, ready for translation
' From Jay Freedman, at https://answers.microsoft.com/en-us/office/forum/office_2007-word/need-word-macro-to-export-and-import-alt-text/af9d12fc-8eab-4343-a25d-f086ae7d73b3

    Dim strPictures As String
    Dim docPictures As Document
    Dim docTranslate As Document
    Dim objInlinePic As InlineShape
    Dim objFloatPic As Shape
    Dim tblTranslate1 As Table
    Dim tblTranslate2 As Table
    Dim tblLoop As Table
    Dim rowCurrent As Row
    Dim oRg As Range

    MsgBox "In the next dialog, select the file containing " & _
        "the pictures whose alt text will be translated."
    strPictures = GetFileName()
    If strPictures = "" Then Exit Sub

    On Error GoTo BadInputFile
    Set docPictures = Documents.Open(FileName:=strPictures)

    Set docTranslate = Documents.Add
    With docTranslate
        ' set up header and footer in translation document
        .Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = _
            "Alt Text of " & docPictures.FullName
        Set oRg = .Sections(1).Footers(wdHeaderFooterPrimary).Range
        oRg.Text = vbTab
        oRg.Collapse wdCollapseEnd
        .Fields.Add Range:=oRg, Type:=wdFieldPage, PreserveFormatting:=False

        ' create two 2x2 tables
        Set tblTranslate1 = .Tables.Add(Range:=.Range, numrows:=2, numcolumns:=2)


        Set oRg = .Range
        oRg.InsertParagraphAfter
        Set oRg = .Range
        oRg.Collapse wdCollapseEnd

        Set tblTranslate2 = .Tables.Add(Range:=oRg, numrows:=2, numcolumns:=2)

        ' put the docPictures path & filename in a document variable
        ' so the import macro can locate it
        .Variables("docPictures").Value = docPictures.FullName
    End With

    ' put a heading row in the table and set borders
    For Each tblLoop In docTranslate.Tables
        With tblLoop
            .Cell(1, 1).Range.Text = "Original Alt Text"
            .Cell(1, 2).Range.Text = "Translated Alt Text"
            .Rows(1).Range.Font.Bold = True
            .Rows(1).HeadingFormat = True
            .Borders.InsideColor = wdColorAutomatic
            .Borders.InsideLineStyle = wdLineStyleSingle
            .Borders.OutsideColor = wdColorAutomatic
            .Borders.OutsideLineStyle = wdLineStyleSingle
        End With
    Next tblLoop

    ' put the alt text of each inline picture into the first column of the table's
    ' last row, and add a new empty row below it
    On Error Resume Next
    For Each objInlinePic In docPictures.InlineShapes
        If objInlinePic.AlternativeText <> "" Then
            tblTranslate1.Rows.Last.Cells(1).Range.Text = objInlinePic.AlternativeText
            If Err.Number <> 0 Then
                MsgBox "Error " & Err.Number & vbCr & Err.Description
                Err.Clear
            End If
            tblTranslate1.Rows.Add
        End If
    Next objInlinePic
    tblTranslate1.Rows.Last.Delete

    ' put the alt text of each floating picture into the first column of the table's
    ' last row, and add a new empty row below it
    On Error Resume Next
    For Each objFloatPic In docPictures.Shapes
        If objFloatPic.AlternativeText <> "" Then
            tblTranslate2.Rows.Last.Cells(1).Range.Text = objFloatPic.AlternativeText
            If Err.Number <> 0 Then
                MsgBox "Error " & Err.Number & vbCr & Err.Description
                Err.Clear
            End If
            tblTranslate2.Rows.Add
        End If
    Next objFloatPic
    tblTranslate2.Rows.Last.Delete

    docPictures.Close wdDoNotSaveChanges
    docTranslate.Save

    Exit Sub

BadInputFile:
    MsgBox "The file " & strPictures & " could not be opened." & _
        vbCr & "Error " & Err.Number & vbCr & Err.Description
End Sub

Function GetFileName() As String
    Dim dlg As FileDialog

    Set dlg = Application.FileDialog(msoFileDialogFilePicker)
    If dlg.Show <> -1 Then
        GetFileName = ""
    Else
        GetFileName = dlg.SelectedItems(1)
    End If
End Function

[Links last checked August 2018]