Results 1 to 10 of 10

save as vba

Threaded View

  1. #1
    Registered User
    Join Date
    08-03-2015
    Location
    Aalst,Belgium
    MS-Off Ver
    2003
    Posts
    14

    save as vba

    Hi I am trying to write vba to save excel file with the prompt save as.
    Included is the filename (based on cell value I6) that will appear in the save as prompt.
    Problem is that i want the saveas prompt to save the excel file in the folder named in cell P6 where the original excelfile which include this vba script is located...

    My scripts generates the save as prompt but not in the right folder...

    Can somenone help me out please?

    Thanks in advance!!

    Here is my code:
    Private Sub cbsaveas_Click()
    Dim wb As Workbook
        Dim NewFileName As String
        Dim NewFileFilter As String
        Dim myTitle As String
        Dim FileSaveName As Variant
        Dim NewFileFormat As Long
       
        Set wb = ThisWorkbook
        If Application.Version >= 12 Then   'Version 12 is xl2007
          'Note: If file extension not included in B18 then concatenate it
          NewFileName = wb.Sheets("Hoofdblad prestudie").Range("I6").Value & ".xlsm"
          NewFileFilter = "Excel Macro-Enabled workbook (*.xlsm), *.xlsm"
          NewFileFormat = 52
        Else
          
          NewFileName = wb.Sheets("Hoofdblad prestudie").Range("I6").Value & ".xls"
          NewFileFilter = "Microsoft Excel Workbook (*.xls), *.xls"
          NewFileFormat = xlNormal
        End If
       
        myTitle = wb.Sheets("Hoofdblad prestudie").Range("P6").Value
       
        FileSaveName = Application.GetSaveAsFilename _
                (InitialFileName:=NewFileName, _
                 FileFilter:=NewFileFilter, _
                 Title:=myTitle)
        If Not FileSaveName = False Then
          wb.SaveAs FileName:=FileSaveName, _
                        FileFormat:=NewFileFormat
        Else
          Msgbox "Calculatie is niet bewaard. Gebruiker heeft het bewaren gecanceled."
        End If
    
    End Sub
    Last edited by michelleblanc; 10-18-2017 at 07:01 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 04-29-2016, 11:55 AM
  2. [SOLVED] Need to loop a macro to save images to file - but save to user defined directory.
    By superfurry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2015, 07:49 AM
  3. Macro to Auto save a backup copy in a seperate location OR save file with a pop up
    By kdsanderson30 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-12-2014, 12:38 PM
  4. Templates - Forcing Save as rather than Save on first save
    By Spitinyari in forum Excel General
    Replies: 4
    Last Post: 04-26-2012, 11:32 AM
  5. Disable Save As and Save - enable Save via button
    By LampCommandr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-07-2011, 05:42 PM
  6. [SOLVED] How to diasble save and save as menu but allow a save button
    By hon123456 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2006, 04:55 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