Ana içeriğe atla

Excel dosyasını hücre değeriyle nasıl kaydedebilirim?

Bir çalışma kitabını kullandığınızda, Excel dosyasını hücre içeriğine göre kaydetmeyi hiç düşündünüz mü? Örneğin, A1 hücresinde "Satış fiyatı" var ve çalışma kitabını Satış fiyatı adı olarak kaydetmek istiyorsunuz. Elbette, adı Farklı Kaydet iletişim kutusuna yazabilir ve ardından kaydedebilirsiniz. Ancak bu, iş miktarınızda verimsiz bir yöntem olacaktır. Bugün bunu çözmek için hızlı bir numaradan bahsedeceğim.

VBA kodunu kullanarak Excel dosyasını belirli hücre değeriyle kaydedin


ok mavi sağ balon VBA kodunu kullanarak Excel dosyasını belirli hücre değeriyle kaydedin

Aşağıdaki VBA kodu, çalışma kitabınızı belirli bir hücre değeriyle kaydetmenize yardımcı olabilir, lütfen aşağıdaki işlemleri gerçekleştirin:

1. Basılı tutun ALT + F11 tuşlarını açmak için Uygulamalar için Microsoft Visual Basic penceresi.

2. tıklayın Ekle > modülve aşağıdaki kodu Modül Penceresi.

VBA kodu: Excel dosyasını belirli hücre değeriyle kaydedin

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. Ve sonra tuşuna basın. F5 kodu yürütmek için anahtar ve çalışma kitabınız A1 hücresinin hücre içeriği olarak adlandırılmıştır. Ekran görüntüsüne bakın:

hücre değeri-1 ile belge-kaydetme

Notlar:

1. Yukarıdaki kodda A1'i diğer hücre referansına değiştirerek dosya adı olarak herhangi bir hücre değerini belirtebilirsiniz.

2. Etkin çalışma kitabınız şu klasörüne kaydedilecektir: C: \ Kullanıcılar \ dt \ Masaüstü \ bilgilerim \ (son eğik çizgi yerine konumunuzu yapıştırdığınızda kalmalıdır), ihtiyacınıza giden yolu değiştirebilirsiniz.


İlgili yazılar:

Excel'de tarih ve saatle dosya nasıl kaydedilir?

Excel'de başlık çubuğunda veya araç çubuğunda dosya yolu nasıl gösterilir?

En İyi Ofis Üretkenlik Araçları

🤖 Kutools AI Yardımcısı: Aşağıdakilere dayalı olarak veri analizinde devrim yaratın: Akıllı Yürütme   |  Kodunu oluşturun  |  Özel Formüller Oluşturun  |  Verileri Analiz Edin ve Grafikler Oluşturun  |  Kutools İşlevlerini Çağır...
Popüler Özellikler: Yinelenenleri Bul, Vurgula veya Tanımla   |  Boş Satırları Sil   |  Veri Kaybı Olmadan Sütunları veya Hücreleri Birleştirin   |   Formülsüz Tur ...
Süper Arama: Çoklu Ölçütlü VLookup    Çoklu Değer VLookup  |   Birden Çok Sayfada VLookup   |   Bulanık Arama ....
Gelişmiş Açılır Liste: Hızla Açılır Liste Oluşturun   |  Bağımlı Açılır Liste   |  Çoklu Seçim Açılır Liste ....
Sütun Yöneticisi: Belirli Sayıda Sütun Ekleme  |  Sütunları Taşı  |  Gizli Sütunların Görünürlük Durumunu Değiştir  |  Aralıkları ve Sütunları Karşılaştırın ...
Öne Çıkan Özellikler: Izgara Odağı   |  Tasarım görünümü   |   Büyük Formül Çubuğu    Çalışma Kitabı ve Sayfa Yöneticisi   |  Kaynak Kütüphanesi (Otomatik metin)   |  Tarih Seçici   |  Çalışma Sayfalarını Birleştirin   |  Hücreleri Şifrele/Şifresini Çöz    E-postaları Listeye Göre Gönder   |  Süper Filtre   |   Özel Filtre (kalın/italik/üstü çizili filtre...) ...
En İyi 15 Araç Seti12 Metin Tools (Metin ekle, Karakterleri Kaldır, ...)   |   50+ Grafik Türleri (Gantt şeması, ...)   |   40+ Pratik Formüller (Yaşı doğum gününe göre hesapla, ...)   |   19 sokma Tools (QR Kodunu Girin, Yoldan Resim Ekle, ...)   |   12 Dönüştürme Tools (Sayılardan Kelimelere, Para Birimi Dönüştürme, ...)   |   7 Birleştir ve Böl Tools (Gelişmiş Kombine Satırları, Bölünmüş hücreler, ...)   |   ... ve dahası

Kutools for Excel ile Excel Becerilerinizi Güçlendirin ve Daha Önce Hiç Olmadığı Gibi Verimliliği Deneyimleyin. Kutools for Excel, Üretkenliği Artırmak ve Zamandan Tasarruf Etmek için 300'den Fazla Gelişmiş Özellik Sunar.  En Çok İhtiyacınız Olan Özelliği Almak İçin Buraya Tıklayın...

Açıklama


Office Tab, Office'e Sekmeli Arayüz Getirir ve İşinizi Çok Daha Kolay Hale Getirir

  • Word, Excel, PowerPoint'te sekmeli düzenlemeyi ve okumayı etkinleştirin, Publisher, Access, Visio ve Project.
  • Yeni pencereler yerine aynı pencerenin yeni sekmelerinde birden çok belge açın ve oluşturun.
  • Üretkenliğinizi% 50 artırır ve her gün sizin için yüzlerce fare tıklamasını azaltır!
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