Skip i'r prif gynnwys

Sut i arbed ffeil Excel gyda gwerth celloedd?

Pan ddefnyddiwch lyfr gwaith, a ydych erioed wedi meddwl arbed y ffeil Excel yn seiliedig ar gynnwys cell? Er enghraifft, mae gennych “bris gwerthu” yng nghell A1, a hoffech chi arbed y llyfr gwaith fel yr enw Pris gwerthu. Wrth gwrs, gallwch chi deipio'r enw yn y dialog Save As, ac yna ei gadw. Ond bydd hwn yn ddull aneffeithlon yn eich gwaith. Heddiw, byddaf yn siarad am dric cyflym i'w ddatrys.

Cadwch ffeil Excel gyda gwerth celloedd penodol trwy ddefnyddio cod VBA


swigen dde glas saeth Cadwch ffeil Excel gyda gwerth celloedd penodol trwy ddefnyddio cod VBA

Efallai y bydd y cod VBA canlynol yn eich helpu i arbed eich llyfr gwaith gyda gwerth celloedd penodol, gwnewch fel a ganlyn:

1. Daliwch i lawr y ALT + F11 allweddi i agor y Ffenestr Microsoft Visual Basic for Applications.

2. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Ffenestr Modiwl.

Cod VBA: Cadw ffeil Excel gyda gwerth celloedd penodol

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. Ac yna pwyswch F5 allwedd i weithredu'r cod, ac mae eich llyfr gwaith wedi'i enwi fel cynnwys celloedd cell A1. Gweler y screenshot:

doc-arbed-gyda-gell-werth-1

Nodiadau:

1. Gallwch nodi unrhyw werth cell fel enw'r ffeil trwy addasu'r A1 i gyfeirnod cell arall yn y cod uchod.

2. Bydd eich llyfr gwaith gweithredol yn cael ei gadw yn ffolder C: \ Defnyddwyr \ dt \ Penbwrdd \ fy ngwybodaeth \ (rhaid aros y slaes olaf pan fyddwch chi'n pastio'ch lleoliad yn ei le), gallwch newid y llwybr i'ch angen.


Erthyglau cysylltiedig:

Sut i gadw ffeil gyda dyddiad ac amser yn Excel?

Sut i ddangos llwybr ffeil yn y bar teitl neu'r bar offer yn Excel?

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
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