Workbook.Saveas Filename issue

gvansly1

New Member
Joined
Jun 10, 2016
Messages
3
Hey All:
Total newb to macros question, so please be patient, trying to learn
I recorded a macro that opens and formats a worksheet then saves as a .csv and .xlsx in a specific file path. I sandwiched this recoded macro inside an Application.FileDialog.
The problem occurs when running the macro more than once with different named worksheets it is trying to overwrite the previously saved worksheets, because the ActiveWorkbook.Saveas Filename:= code is what was recorded in the macro
I’ve search everywhere for a solution with no luck. Any ideas? I have attached a link below, hopefully I linked it correctly.
https://www.dropbox.com/s/67wv969mrcrgzmz/Code.txt?dl=0
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
post the code between codetags here
 
Upvote 0
Code:
Sub Format_The_WOSY()
    Dim xlFileName As String
    Dim fd As Office.FileDialog
    Dim wb As Workbook

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    With fd

        .AllowMultiSelect = False
        .Title = "Please select the latest WOSY file"
        .Filters.Add "Excel", "*.xls*"
        .Filters.Add "All", "*.*"

        If .Show Then
           xlFileName = .SelectedItems(1)
        Else
           'if user pressed CANCEL - exit sub
           MsgBox "User pressed CANCEL"
           Exit Sub
        End If

    End With

    'Tries to open workbook with choosen file name
    On Error Resume Next
    Set wb = Workbooks.Open(xlFileName)
    On Error GoTo 0

    'If we can't find workbook with choosen path, exit Sub
    If wb Is Nothing Then
        MsgBox "Can't find file"
        Exit Sub
    End If
    
        'Find and replace here
    Cells.Select
    Selection.Replace What:=",", Replacement:=", ", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        'Format date here
    Columns("N:N").Select
    Selection.NumberFormat = "[$-10484]yyyy-mm-dd;@"
    Selection.Copy
    
        'Copy the date format and paste to the other Date columns
        
        Columns("P:P").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    
    
        Columns("R:R").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
             
             
        Columns("T:T").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
                 
    Application.CutCopyMode = False
    
    'Save to network library as .xlxs and .csv formats
    
            ChDir "C:\WOSY"
                ActiveWorkbook.SaveAs Filename:="C:\WOSY\02-09-18 WOSY All.xlsx", FileFormat _
                 :=xlOpenXMLWorkbook, CreateBackup:=False 'change path here
                    Cells.Select
                    
            ChDir "C:\WOSY\CSV"
                ActiveWorkbook.SaveAs Filename:="C:\WOSY\CSV\02-09-18 WOSY All.csv", _
                    FileFormat:=xlCSV, CreateBackup:=False 'change path here
                        Cells.Select
    
      
        'close workbook without saving changes
    wb.Close SaveChanges:=False
    Set wb = Nothing

End Sub
 
Upvote 0
With no responses I'm guessing my question was not clear or just a stupid question to begin with.
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,680
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top