peri hokiperihokiclarustologisticsrimashaop.compola taktis menang gates of olympus x1000 perihokipemain perihoki bongkar trik jepep starlight princess x1000perihoki beri panduan lengkap bermain mahjong ways 2 pgsofttips cara penghasil uang pgsoft mahjong ways 2 perihokimahjong wins 3 perihoki memberikan penggali terbesarfenomena gates of olympus buka peluang besar bagi duta76cara dapat pola emas rahasia di duta7 wild west goldtrik menang pgsoft mahjong ways 2 modal receh maxwin duta76duta76 main pgsoft mahjong ways 2 di sela istirahatscatter hitam mahjong wins 3 spin pasti jepe duta76perihoki spin mahjong ways 2 pgsoft scatter hitam maxwinsimbol mahjong wins 3 yang sering muncul di awal perihokitrik gampang menang mahjong winscuan mahjong wins 3 tanpa hentipola spin taruhan kecil mahjong winsstrategi kunci scatter hitam beruntungacor total mahjong wayskemenangan maksimal mahjong wayskemenangan pria pekanbaru mahjong waysmahjong wins3 fenomena baru sumatera baratmenangkan mahjong dengan lincahmenembus batas keberuntungan mahjong waysmenjajal keberuntungan di mahjong wayspola gratis mahjong ways1scatter hitam senjata rahasia mahjong winsteknik spinning menguntungkan untuk scatter hitamanalisis rtp tertinggi mahjong winsfenomena scatter hitam mahjong winsibu rumah tangga dan keberuntungan mahjongkeseruan main mahjong wins3menang mahjong pengguna baru di sosial mediamenghargai setiap momen di mahjong waysserunya main mahjong di warung internetspin slow motion mancing scatterstrategi jitu maxwin mahjong waysstrategi jitu menang mahjong modal kecil jackpot besaranak kampung papua menggemparkan mahjongkeajaiban scatter hitam mahjong wayskeberhasilan joni mahjong winskejaiban mahjong ways di ujung jalanketua mahjong wins3 kehadiran kemenangan dimulai dari balimahjong kehadiran yang menguntungkanmahjong menggila adat88panduan kilat raih 108 jutatips memenangkan mahjongbarista kopi menang 110 juta spin mahjongdakota76 scatter hitam mahjong wins 3gagal cpns menang mahjong wins 3 rp120 jutakisah karyawan minimarket dapat thr lebih awal mahjong winskisah pelajar sma kuasai mahjong wins 3 inspirasi sekolahkisah penjaga parkir tanah abang motor baru mahjong winskisah sukses ibu rumah tangga bandung mahjong winsmahasiswa kkn beli iphone15 mahjong wins3 dakotamantan anak band influencer mahjong scatter hitampola rtp senin gates of olympus guru matematikaidola scatter hitam gampang meledakidola sensasi jackpotidola pola scatter hitamidola hasilkan jackpot dalam waktu singkatidola mahjong wins 3 bocortukang cuci motor menemukan keberuntungan di mahjong

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: drivers/Session_files_driver.php

Line Number: 108

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Cannot change save handler when headers already sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot start session when headers already sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

Hơn 20 cách Save File bằng VBA Code cực kì đơn giản
MACRO
EXCEL OBJECT
VBA BASIC
VBA FORM
BÀI TẬP
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
MỚI CẬP NHẬT

Hơn 20 cách Save File bằng VBA Code cực kì đơn giản

Trong bài này mình sẽ đưa ra 20 cách lưu file (Save File) bằng lệnh VBA, phương pháp này thường dùng để thay thế cho cách làm thủ công, đó là nhấn phím tắt Ctrt + S hoặc click File -> Save.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Để tránh trường hợp người dùng quên lưu lại nội dung các file Excel đã mở thì ta sẽ sử dụng hai lệnh Save SaveAs trong VBA để lưu tự động.

Cũng có một số trường hợp bạn code VBA và cần mở một file nào đó để lấy nội dung, sau đó sửa nội dung và lưu file lại. Nếu để người dùng làm bằng tay thì có khả năng bị sai, vì vậy ta dùng code sẽ an toàn và chính xác hơn.

1. Lệnh Save trong VBA

Lệnh Save trong VBA sẽ lưu file Excel tương tự như cách nhấp vào biểu tượng Save hoặc sử dụng phím tắt Lưu (CTRL + S).

Bài viết này được đăng tại [free tuts .net]

Lưu một file

Đây là cách lưu đơn giản và thường được sử dụng nhất. Ta sẽ truyền vào tên của file cần lưu.

Workbooks("savefile.xlsm").save

Lưu file đang active

Dành cho trường hợp bạn đang mở nhiều file.

ActiveWorkbook.save

Lưu tất cả file đang mở

Dim wb as workbook
    For Each wb In Application.Workbooks
	wb.Save
Next wb

Lưu các file ở trạng thái ReadOnly

File ở trạng thái ReadOnly là những file bạn đã mở nhưng không làm việc.

Dim wb as workbook

For Each wb In Application.Workbooks
	If not wb ReadOnly then
		wb.Save
	End if
Next wb

Lưu file được lưu bởi một biến

Dim wb as workbook

set wb = workbooks("savefile.xlsm")
wb.save

Lưu file được lưu tên trong chuỗi

Dim wbstring as string

wbstring = "savefile.xlsm"
workbooks(wbstring).save

Lưu file theo thứ tự mở file

workbooks(1).save

Lưu file với tên file nằm trong một cell nào đó

Dim wbstring as string

wbstring = activeworkbook.sheets("sheet1").range("wb_save").value
workbooks(wbstring).save

2. Lệnh Save As trong VBA

Save As là tính năng lưu vào một file mới, còn Save là lưu ghi đè trên file đã lưu.

Lệnh này có công dụng giống như việc thao tác trên menu File -> Save As của Excel.

Cách dùng thì không khác gì so với lệnh Save, có điều bạn phải truyền thêm tham số tên file cần lưu.

Cú pháp như sau:

Object.SaveAs(FileName, FileFormat, Password, WriteResPassword, _
ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, _
AddToMru,TextCodepage, TextVisualLayout, Local)

Mình sẽ không giải thích các tham số, thay vào đó sẽ tìm hiểu thông qua những ví dụ dưới đây.

Save As trên cùng thư mục

ActiveWorkbook.SaveAs Filename:= "new"

' Hoặc

ActiveWorkbook.SaveAs "new"

' Hoặc

Dim wbstring as string

wbstring = "new"
ActiveWorkbook.SaveAs Filename:= wbstring

Save As ở thư mục mới

ActiveWorkbook.SaveAs Filename:= "C:\new"

' Hoặc

Dim wbstring as string

wbstring = "C:\new"
ActiveWorkbook.SaveAs Filename:= wbstring=

Save As ở thư mục mới có chọn đuôi mở rộng

ActiveWorkbook.SaveAs Filename:= "C:\new.xlsx"

' Hoặc

Dim wbstring as string

wbstring = "C:\new.xlsx"
ActiveWorkbook.SaveAs Filename:= wbstring

Bạn cũng có thể sử dụng kết hợp File Format để chỉ định dạng của file.

.xlsx = 51 '(52 for Mac)
.xlsm = 52 '(53 for Mac)
.xlsb = 50 '(51 for Mac)
.xls = 56 '(57 for Mac)

Ví dụ: Lưu dưới dạng mở rộng .xlsx trên Windows

ActiveWorkbook.SaveAs Filename:= "C:\new", FileFormat:= 51

Save As và đặt mật khẩu mở file

ActiveWorkbook.SaveAs Filename:= "C:\new.xlsx", Password:= "password"

Save As và đặt mật khẩu ghi file

Nếu mật khẩu bạn nhập để mở file không đúng thì nó sẽ chuyển sang chế độ Read Only.

ActiveWorkbook.SaveAs Filename:= "C:\new.xlsx", WriteRes:= "password"

Save As chế độ read only

ActiveWorkbook.SaveAs Filename:= "C:\new.xlsx", ReadOnlyRecommended:= TRUE

3. Một vài ví dụ về Save File khác trong VBA

Tạo hộp thoại Save As

Application.GetSaveAsFilename

Tạo hộp thoại Save As kèm tên file mặc định

Application.GetSaveAsFilename InitialFilename:="test.xlsx"

Tạo và lưu file mới

Dim wb As Workbook

Set wb = Workbooks.Add
Application.DisplayAlerts = False
wb.SaveAs Filename:=”c:\Test1.xlsx”
Application.DisplayAlerts = True

Xóa cảnh báo khi save

Khi bạn làm việc với tính năng Save trong VBA, bạn có thể gặp nhiều cảnh báo hoặc Lời nhắc khi lưu. Để tắt những điều này thì hãy thêm dòng mã này:

Application.DisplayAlerts=False

Mở lại sẽ là:

Application.DisplayAlerts=True

Trên là tập hợp hơn 20 trường hợp Save File Excel bằng VBA code. Đây là nội dung mình sưu tầm lại ở các trang nước ngoài trên mạng.

Cùng chuyên mục:

Cách chèn link ảnh vào Excel trên máy tính

Cách chèn link ảnh vào Excel trên máy tính

Ngoài ra, bài viết còn hướng dẫn cách chèn link ảnh trực tuyến hàng loạt…

Cách tách và gộp ô trong Excel

Cách tách và gộp ô trong Excel

Trong bảng tính Microsoft Excel, có thể sẽ có lúc các bạn cần tách ô…

Hàm MONTH() trong Excel

Hàm MONTH() trong Excel

Cách dùng hàm MONTH() trong Excel

Hàm YEAR () trong Excel

Hàm YEAR () trong Excel

Cách dùng hàm YEAR () trong Excel

Hàm HLOOKUP() trong Excel

Hàm HLOOKUP() trong Excel

Cách dùng hàm HLOOKUP() trong Excel

Hàm VLOOKUP() trong Excel

Hàm VLOOKUP() trong Excel

Cách dùng hàm VLOOKUP() trong Excel

Hàm LOOKUP() trong Excel

Hàm LOOKUP() trong Excel

Cách dùng hàm LOOKUP() trong Excel

Hàm ABS() trong Excel

Hàm ABS() trong Excel

Cách dùng hàm ABS() trong Excel

Hàm SUM() trong Excel

Hàm SUM() trong Excel

Cách dùng hàm SUM() trong Excel

Hàm SQRT() trong Excel

Hàm SQRT() trong Excel

Cách dùng hàm SQRT() trong Excel

Hàm MOD() trong Excel

Hàm MOD() trong Excel

Cách dùng hàm MOD() trong Excel

Hàm SUMIF() trong Excel

Hàm SUMIF() trong Excel

Cách dùng hàm SUMIF() trong Excel

Hàm SUBTOTAL() trong Excel

Hàm SUBTOTAL() trong Excel

Cách dùng hàm SUBTOTAL() trong Excel

Hàm ROUND() trong Excel

Hàm ROUND() trong Excel

Cách dùng hàm ROUND() trong Excel

Hàm SUMPRODUCT() trong Excel

Hàm SUMPRODUCT() trong Excel

Cách dùng hàm SUMPRODUCT() trong Excel

Hàm COUNT() trong Excel

Hàm COUNT() trong Excel

Cách dùng hàm COUNT() trong Excel

Hàm COUNTA() trong Excel

Hàm COUNTA() trong Excel

Cách dùng hàm COUNTA() trong Excel

Hàm COUNTBLANK() trong Excel

Hàm COUNTBLANK() trong Excel

Cách dùng hàm COUNTBLANK() trong Excel

Hàm MAX() trong Excel

Hàm MAX() trong Excel

Cách dùng hàm MAX() trong Excel

Hàm MIN() trong Excel

Hàm MIN() trong Excel

Cách dùng hàm MIN() trong Excel

Top