我正在嘗試自動化一個程序。
此問題的關注領域是驗證活動作業簿是否是我們共享驅動器中正確檔案夾中的正確作業簿。否則,用戶將保存資料并且不會共享。確保資料輸入的安全措施。
一些用戶將上述“活動作業簿”的副本從共享驅動器保存到他們的 PC,這會導致資料丟失。
如今,人們對 IT 不安全,但害怕不熟悉的自動化功能。為了適應這些情況,我想使用一個訊息框來提醒用戶他們不會將資料保存在組檔案中,然后詢問他們是否要打開該檔案。點擊“是”后,另一個檔案將打開,同時打開現有檔案。選擇“否”或“取消”將結束 sub。
目標:
- 使用訊息框提醒用戶他們沒有處理共享檔案。選擇后,是按鈕將打開正確的檔案。
代碼(在作業簿中):
Private Sub Workbook_Open()
Dim Sheet1 As Worksheet
Set Sheet1 = Sheets("Invoices")
Dim folpath As String
Dim mypath As String
Application.ScreenUpdating = False
folpath = "K:\Purchasing_Utilities\1_UTILITIES\4_VENDOR_INVOICES\GHOST_CARD\Active_Pay_Tracker_22.xlsm"
mypath = Application.ActiveWorkbook.FullName
If mypath = folpath Then
GoTo Skip
Else
MsgBox "This file source is a locally saved file. To share changes, please open the Tracker in the K: drive." _
& " Would you like the system to open this file now?", VbMsgBoxStyle = vbOKCancel vbCritical
'Here is where I am trying to get the message box to open the document
Skip
Sheet1.Range("P:P").Sort Key1:=Sheet1.Range("P:P"), Order1:=xlAscending, Header:=xlYes
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Activate
Application.ScreenUpdating = True
uj5u.com熱心網友回復:
只是一個例子:
Result = MsgBox("This file source is a locally saved file. To share changes, please open the Tracker in the K: drive. Would you like the system to open this file now?", vbOKCancel vbCritical)
If Result = vbOKCancel Then
MsgBox "You clicked OK"
Else: MsgBox "You clicked Critical"
End If
這看起來如下:

如果您按“確定”,您會看到以下內容:

因此,如果您想要 ,則vbYes需要將其添加到原始訊息框(當前沒有“是”按鈕)并添加相應的Result處理 ( if Result = vbYes then ... (open file))。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/390960.html
