Skip to main content

Conas comhad Excel le luach cille a shábháil?

Nuair a úsáideann tú leabhar oibre, ar smaoinigh tú riamh an comhad Excel a shábháil bunaithe ar ábhar cille? Mar shampla, tá “Praghas díola” agat i gcill A1, agus ba mhaith leat an leabhar oibre a shábháil mar an t-ainm Praghas díola. Ar ndóigh, is féidir leat an t-ainm a chlóscríobh sa dialóg Save As, agus ansin é a shábháil. Ach beidh sé seo ina mhodh mí-éifeachtach i do mhéid oibre. Inniu, labhróidh mé faoi chleas gasta chun é a réiteach.

Sábháil comhad Excel le luach sonrach cille trí chód VBA a úsáid


mboilgeog cheart gorm saighead Sábháil comhad Excel le luach sonrach cille trí chód VBA a úsáid

D’fhéadfadh an cód VBA seo a leanas cabhrú leat do leabhar oibre a shábháil le luach cille sonraithe, déan mar a leanas le do thoil:

1. Coinnigh síos an ALT + F11 eochracha a oscailt Fuinneog Microsoft Visual Basic for Applications.

2. Cliceáil Ionsáigh > Modúil, agus greamaigh an cód seo a leanas sa Fuinneog an Mhodúil.

Cód VBA: Sábháil comhad Excel le luach sonrach cille

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. Agus ansin brúigh F5 eochair chun an cód a fhorghníomhú, agus ainmníodh do leabhar oibre mar ábhar cille i gcill A1. Féach an pictiúr:

doc-shábháil-le-luach-cille-1

Nótaí:

1. Is féidir leat aon luach cille a shonrú mar ainm an chomhaid ach an A1 a mhodhnú go tagairt cille eile sa chód thuas.

2. Sábhálfar do leabhar oibre gníomhach i bhfillteán na C: \ Úsáideoirí \ dt \ Deisce \ mo chuid faisnéise \ (caithfear an slais dheireanach a choinneáil nuair a ghreamaíonn tú d’áit in áit é), is féidir leat an cosán a athrú go do riachtanas.


Earraí gaolmhara:

Conas an comhad a shábháil le dáta agus le ham in Excel?

Conas cosán comhaid a thaispeáint i mbarra teidil nó i mbarra uirlisí in Excel?

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
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