Ga naar hoofdinhoud

Hoe een Excel-bestand met celwaarde opslaan?

Als u een werkmap gebruikt, heeft u er dan ooit aan gedacht om het Excel-bestand op te slaan op basis van een celinhoud? U hebt bijvoorbeeld "Uitverkoopprijs" in cel A1 en u wilt de werkmap opslaan als de naam Uitverkoopprijs. U kunt de naam natuurlijk in het dialoogvenster Opslaan als typen en vervolgens opslaan. Maar dit zal een inefficiënte methode zijn voor uw hoeveelheid werk. Vandaag zal ik het hebben over een snelle truc om het op te lossen.

Sla Excel-bestand op met een specifieke celwaarde met behulp van VBA-code


pijl blauw rechts bel Sla Excel-bestand op met een specifieke celwaarde met behulp van VBA-code

De volgende VBA-code kan u helpen om uw werkmap op te slaan met een opgegeven celwaarde, doe dit als volgt:

1. Houd de ALT + F11 toetsen om de te openen Microsoft Visual Basic for Applications-venster.

2. Klikken Invoegen > Moduleen plak de volgende code in het Module Venster.

VBA-code: sla Excel-bestand op met een specifieke celwaarde

Private Sub filename_cellvalue()
'Update 20141112
Dim Path As String
Dim filename As String
Path = "C:\Users\dt\Desktop\my information\"
filename = Range("A1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
End Sub

3. En druk vervolgens op F5 toets om de code uit te voeren, en uw werkmap heeft de naam gekregen als de celinhoud van cel A1. Zie screenshot:

doc-opslaan-met-cel-waarde-1

Opmerkingen:

1. U kunt elke celwaarde specificeren als de bestandsnaam door de A1 naar een andere celverwijzing in de bovenstaande code te wijzigen.

2. Uw actieve werkmap wordt opgeslagen in de map van C: \ Users \ dt \ Desktop \ mijn gegevens \ (de laatste schuine streep moet blijven staan ​​als u uw locatie in plaats van deze plakt) locatie, kunt u het pad naar uw behoefte wijzigen.


Gerelateerde artikelen:

Hoe een bestand met datum en tijd in Excel opslaan?

Hoe het bestandspad in de titelbalk of werkbalk in Excel te tonen?

Beste Office-productiviteitstools

🤖 Kutools AI-assistent: Een revolutie teweegbrengen in de data-analyse op basis van: Intelligente uitvoering   |  Genereer code  |  Aangepaste formules maken  |  Analyseer gegevens en genereer grafieken  |  Roep Kutools-functies aan...
Populaire functies: Zoek, markeer of identificeer duplicaten   |  Verwijder lege rijen   |  Combineer kolommen of cellen zonder gegevens te verliezen   |   Ronde zonder formule ...
Super opzoeken: Meerdere criteria VLookup    VLookup met meerdere waarden  |   VOpzoeken over meerdere bladen   |   Fuzzy opzoeken ....
Geavanceerde vervolgkeuzelijst: Maak snel een vervolgkeuzelijst   |  Afhankelijke vervolgkeuzelijst   |  Multi-select vervolgkeuzelijst ....
Kolom Beheerder: Voeg een specifiek aantal kolommen toe  |  Kolommen verplaatsen  |  Schakel de zichtbaarheidsstatus van verborgen kolommen in  |  Vergelijk bereiken en kolommen ...
Uitgelichte functies: Raster focus   |  Ontwerpweergave   |   Grote formulebalk    Werkmap- en bladbeheer   |  resource Library (Auto-tekst)   |  Datumkiezer   |  Combineer werkbladen   |  Cellen coderen/decoderen    Stuur e-mails per lijst   |  Super filter   |   Speciaal filter (filter vet/cursief/doorhalen...) ...
Top 15 gereedschapsets12 Tekst Tools (toe te voegen tekst, Tekens verwijderen, ...)   |   50+ tabel Types (Gantt Chart, ...)   |   40+ Praktisch Formules (Bereken leeftijd op basis van verjaardag, ...)   |   19 Invoeging Tools (QR-code invoegen, Afbeelding invoegen vanaf pad, ...)   |   12 Camper ombouw Tools (Getallen naar woorden, Currency Conversion, ...)   |   7 Samenvoegen en splitsen Tools (Geavanceerd Combineer rijen, Gespleten cellen, ...)   |   ... en meer

Geef uw Excel-vaardigheden een boost met Kutools voor Excel en ervaar efficiëntie als nooit tevoren. Kutools voor Excel biedt meer dan 300 geavanceerde functies om de productiviteit te verhogen en tijd te besparen.  Klik hier om de functie te krijgen die u het meest nodig heeft...

Omschrijving


Office-tabblad Brengt een interface met tabbladen naar Office en maakt uw werk veel gemakkelijker

  • Schakel bewerken en lezen met tabbladen in Word, Excel, PowerPoint in, Publisher, Access, Visio en Project.
  • Open en maak meerdere documenten in nieuwe tabbladen van hetzelfde venster in plaats van in nieuwe vensters.
  • Verhoogt uw productiviteit met 50% en vermindert honderden muisklikken voor u elke dag!
Comments (33)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Zdravím,

mám jednu prosbu ... došel jsem do bodu, kdy mám nastavené ukládání souboru excel u s názvem podle dané buňky, ale nedaří se mi pomocí makra aktualizaci, aby se to uložilo s aktuálním názvem.
Asi dělaám něco při nahrávání makra.
Musím tedy spustit ALT+F11 a následně F5.
Může mi někdo pomoci?
This comment was minimized by the moderator on the site
Hello, Petr,
If you want to auto save the workbook with the changed cell value, please apply the below code:
First, you should right click the sheet name contains the cell value you want to rename based on, and then click View Code to open the Microsoft Visual Basic for Applications window, then copy and paste the below code into the blank sheet code. see screenshot:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim Path As String
    Dim filename As String
    
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Address = "$A$1" Then
        Application.DisplayAlerts = False
        Path = "C:\Users\AddinsVM001\Desktop\Folder-1\"
        filename = Target
        ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsx"
        Application.DisplayAlerts = True
    End If
End Sub

https://www.extendoffice.com/images/stories/comments/comment-skyyang/save-file-with-cell-value.png
After pasting the code, when you change the A1 cell value, a new excel file with this name will be saved into the specific location.

Note: please change the cell value and file path to oyur need.

Please try it, if you have any other problem, please comment here.
This comment was minimized by the moderator on the site
Hi

I want the file "Offerte JCDecaux_" to be automaticly re-named when saving.
This by combining the file name & the result of formula (=TEXT(O9; "aammjj" ) & "." & O10 & "_" & A5) in cell O11 of worksheet OFFERTE.
The end result would for exemple need to be "Offerte JCDecaux_2205004.1_LEENTJE".

How do I do that?
This comment was minimized by the moderator on the site
Hi 
its very helpful for me 
i would like take the filename from an other workbook can anyone show me how to do this 
This comment was minimized by the moderator on the site
I have updated this to work with Excel 2019 and to create a PDF:

Sub FileNameAsCellContent()

Dim userPath As String
Dim FileName1 As String
Dim FileName2 As String

userPath = Environ("UserProfile")

'Edit the save location here with first folder location after C:\Users\[user]\ or leave to save to Desktop
Const LOCATION As String = "\Desktop\"

'Select which cells to use in filename here
Application.DisplayAlerts = False
FileName1 = Range("F5")
FileName2 = Range("B6")

With ActiveSheet

'Edit filename format here or keep as default (default text - text.pdf)
PDFFullName = userPath & LOCATION & FileName1 & " - " & FileName2 & ".pdf"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=PDFFullName, Quality:=xlQualityStandard, OpenAfterPublish:=False
Application.DisplayAlerts = True

End With
End Sub
This comment was minimized by the moderator on the site
Hi, I’m wondering if anyone could help me. I have this pasted into my workbook but it returns a file name of FALSE.xlsm in the Documents folder rather than the specified path.
I had to tweak it to make this work, prior to tweaking it I was getting a Run-time error ‘1004’ Excel cannot access the file.
This is the amended code:
Sub filename_cellvalue()Dim Path As StringDim filename As StringPath = “C:\Users\DC\Documents\Planners\”Filename = Range (“K2”)ActiveWorkbook.SaveAs Filename = (Path & Filename & “.xlsm”)End Sub
Using Excel 2016
Any help would be greatly appreciated.
Thanks in advance
This comment was minimized by the moderator on the site
can anyone please help with a solution, i've managed to get the output correctly if the cell is not blank



Private Sub Saveas()

Dim path As String

Dim filename1 As String



path = "C:\User\Compwork\"



filename1 = path & Range("G4") & " " & "-" & " " & Range("G6") & " " & "-" & " " & Range("H7") & " " & "VTError"

Application.DisplayAlerts = False

ActiveWorkbook.Saveas filename1, FileFormat:=52, CreateBackup:=False

ThisWorkbook.Worksheets("report").ExportAsFixedFormat Type:=x1typePDF, Filename:=filename1

Application.DisplayAlerts = True

ActiveWorkbook.Close



End Sub







However, my problem is I'd like to save a filename without leaving a space if the cell value is NULL for instance, if G6 value is blank then i like to the output "G4-H7 VTError".

Any there a way to approach this?





Thanks.
This comment was minimized by the moderator on the site
can anyone please help with a solution, i've managed to get the output correctly if the cell is not blank

Private Sub Saveas()

Dim path As String

Dim filename1 As String



path = "C:\User\Compwork\"



filename1 = path & Range("G4") & " " & "-" & " " & Range("G6") & " " & "-" & " " & Range("H7") & " " & "VTError"

Application.DisplayAlerts = False

ActiveWorkbook.Saveas filename1, FileFormat:=52, CreateBackup:=False

ThisWorkbook.Worksheets("report").ExportAsFixedFormat Type:=x1typePDF, Filename:=filename1

Application.DisplayAlerts = True

ActiveWorkbook.Close



End Sub



However, my problem is I'd like to save a filename without leaving a space if the cell value is NULL for instance, if G6 value is blank then i like to the output "G4-H7 VTError".
Any there a way to approach this?


Thanks.
This comment was minimized by the moderator on the site
I have a control button for saving as PDF with a specific name to a specific location already working, but I want to modify the code as the filename is the name of the active sheet plus the value of a specific cell from another sheet. How do I do that? This is what I have for saving as PDF:


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:="\\U:\Documents\My_IT_Stuff\T&A\PP11", _
OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub

Thank you!
This comment was minimized by the moderator on the site
Hi. I am very excited it could work but for me in it is saying "BASIC runtime error. Sob-procedure or function procedure not defined." and arrow indicating line 6. What should I do?
This comment was minimized by the moderator on the site
Se a célula de referencia estiver em uma outra planilha já aberta? Como faço?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations