Consulting

Results 1 to 2 of 2

Thread: Macro to rename in "save-as" file.

  1. #1

    Macro to rename in "save-as" file.

    I am new to this forum and have no experience directly in VBA, but I have made some basic Word 2010 macros.

    I have a list of about 300 files that I need to do a save-as in .txt format and save with .txt instead of the current .doc extension. My limited record macro is retaining the name of the file I record the macro on for all of the files and wanting to overwrite which is not what I want it to do.

    Any help to rename would be greatly appreciated.

    Ed

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi Ed,

    Try:
    [vba]Sub DocumentsToText()
    Application.ScreenUpdating = False
    Dim strFolder As String, strFile As String, wdDoc As Document
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    strFile = Dir(strFolder & "\*.doc", vbNormal)
    While strFile <> ""
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
    .SaveAs strFolder & "\" & Split(.Name, ".")(0), FileFormat:=wdFormatText, AddToRecentFiles:=False
    .Close SaveChanges:=False
    End With
    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[/vba]
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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