Giúp code định dạng hệ thống (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

congnguyen88

Thành viên bị đình chỉ hoạt động
Thành viên bị đình chỉ hoạt động
Tham gia
22/7/14
Bài viết
355
Được thích
31
Sub SetCP()
Const HKEY_CURRENT_USER = &H80000001
Set objReg = GetObject("winmgmts:\root\default:StdRegProv")
strKeyPath = "Control Panel\International"
'Decimal symbol
strValueName1 = "sDecimal"
strValue1 = "."
'Digit grouping symbol
strValueName2 = "sThousand"
strValue2 = ","
'Short date
strValueName3 = "sShortDate"
strValue3 = "dd/MM/yyyy"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName1, strValue1
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName2, strValue2
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName3, strValue3
End Sub

Code này thì đúng nhưng còn thiếu ở phần short time, long time, AM symbol, PM symbol
Mình muốn:
- short time= HH:mm
- long time= HH:mm
- AM symbol: trống
- PM symbol: trống
Mong các bạn giúp mình. Xin cảm ơn
cat.jpg
 
Vào RUN, gõ regedit >> OK. Cửa sổ Registry Editor hiện ra tìm tới mục
HKEY_CURRENT_USER\Control Panel\International
Click chuột phải vào International >> Export >> Lưu thành 1 file.reg.
Mở file.reg (bằng notepad) chỉnh sửa giá trị các tham số theo mong muốn. Lưu lại. Sau đó Merge vào reg. Vậy là xong.
Cất file đó đi, khi nào cần lại dùng (thiết lập cho máy tính khác chẳng hạn)
Nếu dùng vba thì nhìn các name ở danh sách rồi làm như đoạn bạn đã có.

Regedit.jpg
 
Upvote 0
Vào RUN, gõ regedit >> OK. Cửa sổ Registry Editor hiện ra tìm tới mục
HKEY_CURRENT_USER\Control Panel\International
Click chuột phải vào International >> Export >> Lưu thành 1 file.reg.
Mở file.reg (bằng notepad) chỉnh sửa giá trị các tham số theo mong muốn. Lưu lại. Sau đó Merge vào reg. Vậy là xong.
Cất file đó đi, khi nào cần lại dùng (thiết lập cho máy tính khác chẳng hạn)
Nếu dùng vba thì nhìn các name ở danh sách rồi làm như đoạn bạn đã có.

View attachment 155637

Ok thank mình lam duoc roi

Sub SetCP()
Const HKEY_CURRENT_USER = &H80000001
Set objReg = GetObject("winmgmts:\root\default:StdRegProv")
strKeyPath = "Control Panel\International"
'Decimal symbol
strValueName1 = "sDecimal"
strValue1 = "."
'Digit grouping symbol
strValueName2 = "sThousand"
strValue2 = ","
'Short date
strValueName3 = "sShortDate"
strValue3 = "dd/MM/yyyy"


'Short time
strValueName4 = "sShortTime"
strValue4 = "HH:mm"


'Long time
strValueName5 = "sTimeFormat"
strValue5 = "HH:mm"


'AM symbol
strValueName6 = "s1159"
strValue6 = ""


'PM symbol
strValueName7 = "s2359"
strValue7 = ""


objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName1, strValue1
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName2, strValue2
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName3, strValue3


objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName4, strValue4
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName5, strValue5
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName6, strValue6
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName7, strValue7
End Sub
 
Upvote 0
Thật bất ngờ với cách dùng VBA để hiệu chỉnh những định dạng ngày, tiền, phân cách của Bác. Tuy chưa thử trực tiếp nhưng với riêng tôi lại có thêm một cách hiệu chỉnh (trực quan theo hướng dẫn của MS, lệnh dos, autoit, vba Excel). Thanks.
Em cũng xin chia sẻ 2 cái sau, em vẫn đang sử dụng hàng ngày ah:

Function ChChuoiSangNgay()
Dim Myrange As Range
'Kiem tra workbook
If Application.Workbooks.Count = 0 Then End
Selection.NumberFormat = "dd/mm/yy"
Set Myrange = Application.Selection
For Each Cell In Myrange.Cells
If Trim(Cell.Text) = "/ /" Or Trim(Cell.Text) = "" Then
Cell.value = ""​
Else
If IsDate(Cell.Text) Then Cell.value = DateValue(Cell.Text)​
End If​
Next​
End Function

Và:

'Chuyen sang dang dd/mm/yyyy
Function ChStringToDate()
Dim Myrange As Range
'Kiem tra workbook
If Application.Workbooks.Count = 0 Then End
Set Myrange = Application.Selection
For Each Cell In Myrange.Cells
On Error Resume Next
Cell.value = stod(Cell.Text)​
Next
Selection.NumberFormat = "dd/mm/yyyy"
Selection.HorizontalAlignment = xlGeneral​
End Function
 
Lần chỉnh sửa cuối:
Upvote 0
Ok thank mình lam duoc roi

Sub SetCP()
Const HKEY_CURRENT_USER = &H80000001
Set objReg = GetObject("winmgmts:\root\default:StdRegProv")
strKeyPath = "Control Panel\International"
'Decimal symbol
strValueName1 = "sDecimal"
strValue1 = "."
'Digit grouping symbol
strValueName2 = "sThousand"
strValue2 = ","
'Short date
strValueName3 = "sShortDate"
strValue3 = "dd/MM/yyyy"


'Short time
strValueName4 = "sShortTime"
strValue4 = "HH:mm"


'Long time
strValueName5 = "sTimeFormat"
strValue5 = "HH:mm"


'AM symbol
strValueName6 = "s1159"
strValue6 = ""


'PM symbol
strValueName7 = "s2359"
strValue7 = ""


objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName1, strValue1
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName2, strValue2
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName3, strValue3


objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName4, strValue4
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName5, strValue5
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName6, strValue6
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName7, strValue7
End Sub
Chào bạn. cho mình hỏi chút, Mình copy đoạn code của bạn và cho chạy trong modul, chạy xong mình k thấy có thay đổi gì, bạn có thể hướng dẫn mình chút đc ko . thanks
 
Upvote 0
Chào bạn. cho mình hỏi chút, Mình copy đoạn code của bạn và cho chạy trong modul, chạy xong mình k thấy có thay đổi gì, bạn có thể hướng dẫn mình chút đc ko . thanks

Bạn chạy xong rồi, Bạn tắt File excel đi mở lên lại mới thấy được nhé
 
Upvote 0
Bạn chạy xong rồi, Bạn tắt File excel đi mở lên lại mới thấy được nhé
Khi mình mở Region trong ControPanel , thay đổi thì nó sẽ tự động cập nhập luôn.
Vậy dựa theo cách này của bạn, liệu có cách nào nó tự cập nhập mà k pải chạy lại file excel đc ko bạn !
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom