+ Reply to Thread
Results 1 to 8 of 8

Macro to open files in folder and Save As if any bold, italics or underline in document

  1. #1
    Registered User
    Join Date
    05-03-2012
    Location
    OZ
    MS-Off Ver
    Excel 2016
    Posts
    18

    Macro to open files in folder and Save As if any bold, italics or underline in document

    Hi, I'm trying to create a macro to browse through and open each of the documents in a folder and search for any bold, italics or underlined text in the document, in which case the file is to be saved with a different filename.

    I have the code for browsing through the documents and for saving as, but don't know how to create the code (similar to an If statement with an OR I guess, but maybe With is more correct in this instance) to check if there is any bold, italics or underlined text in the document.

    Thanks for any help!

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to open files in folder and Save As if any bold, italics or underline in documen

    And what if there is more than one instance of bold, italics or underlined text in the document? What if there's two or more of bold, italics or underlined text in the document, perhaps in different places?
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    05-03-2012
    Location
    OZ
    MS-Off Ver
    Excel 2016
    Posts
    18

    Re: Macro to open files in folder and Save As if any bold, italics or underline in documen

    Hi Paul, thanks for your prompt response. The rest of my code is actually from another post of yours so thanks!!

    If there is at least one instance of either bold or italics or underline then the Save As is to apply.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to open files in folder and Save As if any bold, italics or underline in documen

    But you haven't answered my questions! What happens if there are two of
    • either bold or italics or underline?
    • bold and/or italics and/or underline?

  5. #5
    Registered User
    Join Date
    05-03-2012
    Location
    OZ
    MS-Off Ver
    Excel 2016
    Posts
    18

    Re: Macro to open files in folder and Save As if any bold, italics or underline in documen

    Sorry I should have been more accurate and written "any" in place of "either" i.e. if there is at least one instance of any bold text or italicised text or underlined text then the Save As is to apply.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to open files in folder and Save As if any bold, italics or underline in documen

    And how is the new name determined?

  7. #7
    Registered User
    Join Date
    05-03-2012
    Location
    OZ
    MS-Off Ver
    Excel 2016
    Posts
    18

    Re: Macro to open files in folder and Save As if any bold, italics or underline in documen

    Adding a fixed string to the end of the current filename.

    Current code is:

    Sub FindBoldItalicsUnderlineandSaveAs ()
    Application.ScreenUpdating = False
    Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
    strDocNm = ActiveDocument.FullName
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    strFile = Dir(strFolder & "\*.doc")
    While strFile <> ""
    If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)

    'IF BOLD ITALICS OR UNDERLINE EXECUTE BELOW AND IF NOT JUST CLOSE DOCUMENT

    With wdDoc
    .SaveAs FileName:=strFolder & "\" & strFile & " - B,I,U”
    .Close SaveChanges:=True
    End With
    End If
    strFile = Dir()
    Wend
    Set wdDoc = Nothing
    Application.ScreenUpdating = True
    End Sub


    Function GetFolder() As String
    Dim oFolder As Object
    GetFolder = ""
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
    Set oFolder = Nothing
    End Function

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to open files in folder and Save As if any bold, italics or underline in documen

    In that case, try:
    Please Login or Register  to view this content.
    PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Exact comparison including bold / italics / underline
    By qjawaid in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-30-2014, 07:28 PM
  2. [SOLVED] macro to open all files in a folder, save them, then close them
    By hopefulhart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2013, 06:40 PM
  3. Open every file in the folder, remove merge and wrap, save and close files
    By abdesai in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2013, 04:58 PM
  4. Macro to create a folder and then save all files in that folder
    By gokzee in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-27-2013, 01:49 PM
  5. [SOLVED] A macro that will underline, bold, and change to red color text individual words.....
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2012, 01:48 PM
  6. exce; macro to open, save embedded pdf, word, excel, ppt files to a folder
    By mcledavid in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-16-2009, 05:17 PM
  7. Replies: 2
    Last Post: 02-28-2008, 01:45 PM
  8. bold italics or underline
    By Dorothy in forum Excel General
    Replies: 5
    Last Post: 02-16-2005, 11:28 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1