none
Saveas in Word useing Marco, how do you get a variable to be used as filename RRS feed

Answers

  • >>>How do a select a part of your Word doc that dont change place or length as but change number value as your Saveas doc name useing a Marco 

    According to your description, please correct me if I have any misunderstandings on your question, you could refer to below code:
    Sub Demo()
       With Application.FileDialog(msoFileDialogOpen)
            .AllowMultiSelect = True
            .Filters.Add "Word Document", "*.docx", 1
            .Show
     
            ' Display paths of each file selected
            If .SelectedItems.Count > 0 Then
                Set wordapp = CreateObject("Word.Application")
                For lngCount = 1 To .SelectedItems.Count
                    filePath = .SelectedItems(lngCount)
                    
                    Set worddoc = wordapp.Documents.Open(.SelectedItems(lngCount))
                    filePath = Replace(filePath, worddoc.Name, lngCount & ".docx")
                    
                    worddoc.SaveAs filePath
                    worddoc.Close
                Next lngCount
                wordapp.Quit
                Set wordapp = Nothing
            End If
     
        End With
    End Sub

    For more information, click here to refer about Application.FileDialog Property (Excel)

    In addition I suggest that you could provide more information about your issue, for example sample code, screenshot etc., that will help us reproduce and resolve it.

    Thanks for your understanding.
    • Marked as answer by David_JunFeng Tuesday, June 14, 2016 2:07 PM
    Friday, June 3, 2016 5:31 AM

All replies

  • Hi ErikWH,

    Based on your description, you wanted to use Macro to get your result.

    This is the forum to discuss questions and feedback for Microsoft Excel, I'll move your question to the MSDN forum for Excel

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,

    Emi Zhang
    TechNet Community Support


    Please mark the reply as an answer if you find it is helpful.

    If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, June 2, 2016 7:31 AM
  • Could you please elaborate on this? Maybe a screenshot and what you really want to accomplish?

    Best regards, George

    Thursday, June 2, 2016 12:26 PM
  • >>>How do a select a part of your Word doc that dont change place or length as but change number value as your Saveas doc name useing a Marco 

    According to your description, please correct me if I have any misunderstandings on your question, you could refer to below code:
    Sub Demo()
       With Application.FileDialog(msoFileDialogOpen)
            .AllowMultiSelect = True
            .Filters.Add "Word Document", "*.docx", 1
            .Show
     
            ' Display paths of each file selected
            If .SelectedItems.Count > 0 Then
                Set wordapp = CreateObject("Word.Application")
                For lngCount = 1 To .SelectedItems.Count
                    filePath = .SelectedItems(lngCount)
                    
                    Set worddoc = wordapp.Documents.Open(.SelectedItems(lngCount))
                    filePath = Replace(filePath, worddoc.Name, lngCount & ".docx")
                    
                    worddoc.SaveAs filePath
                    worddoc.Close
                Next lngCount
                wordapp.Quit
                Set wordapp = Nothing
            End If
     
        End With
    End Sub

    For more information, click here to refer about Application.FileDialog Property (Excel)

    In addition I suggest that you could provide more information about your issue, for example sample code, screenshot etc., that will help us reproduce and resolve it.

    Thanks for your understanding.
    • Marked as answer by David_JunFeng Tuesday, June 14, 2016 2:07 PM
    Friday, June 3, 2016 5:31 AM