[macro VBA] save workbook cell name

Solved
BastienP Posted messages 4 Status Member -  
 FAB -
Hello,

I'm looking for how to code to save my workbook with a name that would be the value of a cell (number or text) or even preferably the name of a sheet in this workbook.

I thought about defining a variable but this does not work in the code:

ActiveWorkbook.SaveAs Filename:= _
"name.xls"

If anyone has an idea for me...
Thanks and have a good evening!!

10 answers

  1. eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   7 281
     
    Hello,

    ActiveWorkbook.SaveAs Filename:=[A1].Value
    works very well with test.xls in A1.
    If you have a number or text without .xls in A1, you need to add it:
    ActiveWorkbook.SaveAs Filename:=[A1].Value & ".xls"
    You can complete the name with the directory path...

    eric
    24
    1. eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   7 281 > dokayun
       
      Hello,

      Either you put the path and the filename in 2 cells of a sheet, or in VBA variables, or you mix them.
      For example, with the path in a variable and the filename in Sheet1!A1:
      sub save
      dim path as string
      path = "C:\Users\Family MOULA\Documents\project\Eve\"
      ActiveWorkbook.SaveAs Filename:=path & Worksheets("Sheet1").[A1].Value
      end sub

      eric
      0
    2. Creatif911 Posted messages 1 Status Member > eriiic Posted messages 24581 Registration date   Status Contributor Last intervention  
       
      Hello,
      Is it possible when specifying the file path for saving, to determine a part of this file path from a variable in a cell of your Excel spreadsheet?

      Dim chemin As String
      chemin = "C:\Users\Louis\Desktop\Louis Nadeau\Travail\Entreprises\Matrixcel\Clients\resiver\Diagnostiques\"
      ActiveWorkbook.SaveAs Filename:=chemin & Worksheets("diagnostique").[c2] & [" "] & [c4].Value



      Example: My clients are all in the same folder named "client"

      client a
      client b
      client c


      In my spreadsheet, I have a place where I write the client's name... I would like to be able to indicate from this cell the exact location to save the document...
      e.g., C:\Users\Louis\Desktop\Louis\Travail\Entreprises\Matrixcel\Clients\ ???? \diagnostique\"

      I have made attempts by naming a variable... but I am really not a programmer... so if you have 2 seconds to help me, it would be greatly appreciated.
      0