Results 1 to 5 of 5
  1. #1
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60

    Access Change Excel File Name

    Ok, I have a export module in Access. This takes data from at least 10 different queries and paste into excel file. This works good.

    As part of this, I use a input box to select which files to select

    Code:
    Dim RFQNUM As String
    RFQNUM = InputBox("Enter RFQ Number")
    Code:
    Set rs = CurrentDb.OpenRecordset("SELECT FIELD FROM QUERY WHERE FIELD='" & RFQNUM & "'") '
    Then at the end of the code, I close everything.




    Code:
    xlw.Close True   ' close the EXCEL file and save the new data
    Set xlw = Nothing
    If blnEXCEL = True Then xlx.Quit
    Set xlx = Nothing
    
    
    End Function
    I want to use this excel file as the template. I would like to do is rename the excel file before saving it. It would be great if I could rename as the input box value. It ok to be in the same folder, or maybe it would be better to move it.

    I am still kind of new to VBA. My understanding is getting better, but I still cant don't know how to write it.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,281
    Use the SaveAs option for the excel file.
    That will keep the template ready for the next output.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60
    Thank you...I am just not sure how to do that part.

    This code saves it and closes the file. I guess I can leave it open, but would rather see if I can automatically save the file based on the textbox value.

    Quote Originally Posted by Welshgasman View Post
    Use the SaveAs option for the excel file.
    That will keep the template ready for the next output.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,281
    Quote Originally Posted by cbuechner View Post
    Thank you...I am just not sure how to do that part.

    This code saves it and closes the file. I guess I can leave it open, but would rather see if I can automatically save the file based on the textbox value.
    You supply the textbox value as part/all of the filename you are saving as.?
    Google Excel Save As VBA and see what that produces.

    Here is one of mine (but run in Excel VBA)
    Code:
    Application.StatusBar = "Saving csv file as " & strOutFile
    ' Save the CSV version
    ActiveWorkbook.SaveAs Filename:=strOutFile, FileFormat:=xlCSV, _
        CreateBackup:=False
    ' And save as an Excel file
    ' Need to rename Sheet 1 as csv saves makes it the csv name
    Application.StatusBar = "Saving Excel file as " & strMainFile
    Sheets(1).Name = "Output"
    ActiveWorkbook.SaveAs Filename:=strMainFile, FileFormat:=xlNormal
    and here I set the value for strOutFile. Note, I needed my file as a CSV file. You would choose an excel format.

    strOutFile = Range("K1").Value

    You need to modify to suit.

    Tip: Google is your friend. Searching for 'Excel Save As VBA' get you plenty of hits to look at.
    Last edited by Welshgasman; 12-16-2021 at 04:21 PM.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60
    Yes and I am much better at excel, however, I was under the impression the code would be different. If excel code works for this purpose, I will give that a try. Thank you!


    Quote Originally Posted by Welshgasman View Post
    You supply the textbox value as part/all of the filename you are saving as.?
    Google Excel Save As VBA and see what that produces.

    Here is one of mine (but run in Excel VBA)
    [code]
    Application.StatusBar = "Saving csv file as " & strOutFile
    ' Save the CSV version
    ActiveWorkbook.SaveAs Filename:=strOutFile, FileFormat:=xlCSV, _
    CreateBackup:=False
    ' And save as an Excel file
    ' Need to rename Sheet 1 as csv saves makes it the csv name
    Application.StatusBar = "Saving Excel file as " & strMainFile
    Sheets(1).Name = "Output"
    ActiveWorkbook.SaveAs Filename:=strMainFile, FileFormat:=xlNormal
    [code]
    and here I set the value for strOutFile. Note, I needed my file as a CSV file. You would choose an excel format.

    strOutFile = Range("K1").Value

    You need to modify to suit.

    Tip: Google is your friend. Searching for 'Excel Save As VBA' get you plenty of hits to look at.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 38
    Last Post: 10-13-2020, 09:30 AM
  2. Replies: 2
    Last Post: 12-15-2017, 08:09 PM
  3. Replies: 6
    Last Post: 09-14-2017, 07:31 AM
  4. Replies: 34
    Last Post: 08-09-2017, 09:57 AM
  5. Replies: 1
    Last Post: 09-17-2014, 04:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums