Run time error 1004 for saving excel file (VBA required)

后端 未结 2 1212
北荒
北荒 2021-01-06 12:39

I was wondering if anyone knows how to use vba to save a .txt file that is opened in excel?

I have tried writing a coding with a UserForm, but it is giv

2条回答
  •  长发绾君心
    2021-01-06 12:57

    I'm unsure why you're using Workbooks.Open after ActiveWorkbook.SaveAs. If the workbook is already open, isn't this unnecessary?

    Anyway, to prompt the user for a save location try modifying the following as you require:

    Sub DoooooooooooooooooooIt()
    
        Dim fd As FileDialog
    
        Set fd = Application.FileDialog(msoFileDialogSaveAs)
    
        With fd
            .Show
            If .SelectedItems.Count > 0 Then
                Debug.Print .SelectedItems(1)
            End If
        End With
    
    End Sub
    

提交回复
热议问题