VBA 从另一个 Sheet 调用标签
VBA to Call Label from Another Sheet
只是我需要知道我是否可以调用位于同一工作簿上另一个 sheet 中的特定标签。
我知道我可以很容易地调用同一个 sheet 中的标签,但是来自另一个 sheet 的标签呢??
或者还有其他类似的方法吗
例如:
通常当我们是 运行 一个代码时,我们可以通过调用它的子例程名称来调用另一个模块代码,例如,标签是一种跳过行并从特定行开始的方法
Dim AnswerP As String
AnswerP = Application.InputBox("Do You Have a file to be uploaded! Please type yes ", Default:="yes", Title:="Checking File Existance!")
'If Answer is Yes Upload file and Goto Another File (Mobile label)
If AnswerP = "yes" Then
Z_Import_Package_2 'Calling another module code by its name
Dim UploadedP As String
UploadedP = "Selected"
GoTo Mobile 'Label
ElseIf AnswerP = "no" Then 'Checking Next Mobile File
UploadedP = "Skipped"
Dim LastRowCP As Long
LastRowCP = Ssheet4.Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
Ssheet4.Range("C3:C" & LastRowCP).Copy Destination:=DestShtBPS.Cells(LR_DestShtB, "C")
MobileF:
Dim AnswerM As String
AnswerM = Application.InputBox("Do You Have another File to be uploaded! Please type yes ", Default:="yes", Title:="Checking File Existance!")
If AnswerM = "yes" Then
Z_Import_Mobile_2 'Calling another module code by its name
所以我可以直接从另一个 sheet 调用 MobileF Label 吗?
因为调用子例程标签将从一开始就调用完整代码,这不是 diresed
Goto
并不是真正好的流量控制方法:我们有很多更好的选择。关于 Goto
在错误处理之外唯一需要的是跳出多个嵌套循环。建议您重组代码以使用常规流程控制 (if/then) 并将需要从多个位置调用的任何代码分解为独立方法(子或函数)
If MsgBox("Do You Have a file to be uploaded?", _
vbQuestion + vbYesNo, "Checking File") = vbYes Then
Z_Import_Package_2 'Calling another module code by its name
Dim UploadedP As String
UploadedP = "Selected"
MobileF 'call MobileF
Else
UploadedP = "Skipped"
Dim LastRowCP As Long
LastRowCP = Ssheet4.Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
Ssheet4.Range("C3:C" & LastRowCP).Copy Destination:=DestShtBPS.Cells(LR_DestShtB, "C")
'...
'...
将 MobileF 移至独立 Sub:
Sub MobileF()
If MsgBox("Do You Have another File to be uploaded?", _
vbQuestion + vbYesNo, _
"Checking File Existance!") = vbYes Then
Z_Import_Mobile_2
End If
End Sub
只是我需要知道我是否可以调用位于同一工作簿上另一个 sheet 中的特定标签。
我知道我可以很容易地调用同一个 sheet 中的标签,但是来自另一个 sheet 的标签呢??
或者还有其他类似的方法吗
例如: 通常当我们是 运行 一个代码时,我们可以通过调用它的子例程名称来调用另一个模块代码,例如,标签是一种跳过行并从特定行开始的方法
Dim AnswerP As String
AnswerP = Application.InputBox("Do You Have a file to be uploaded! Please type yes ", Default:="yes", Title:="Checking File Existance!")
'If Answer is Yes Upload file and Goto Another File (Mobile label)
If AnswerP = "yes" Then
Z_Import_Package_2 'Calling another module code by its name
Dim UploadedP As String
UploadedP = "Selected"
GoTo Mobile 'Label
ElseIf AnswerP = "no" Then 'Checking Next Mobile File
UploadedP = "Skipped"
Dim LastRowCP As Long
LastRowCP = Ssheet4.Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
Ssheet4.Range("C3:C" & LastRowCP).Copy Destination:=DestShtBPS.Cells(LR_DestShtB, "C")
MobileF:
Dim AnswerM As String
AnswerM = Application.InputBox("Do You Have another File to be uploaded! Please type yes ", Default:="yes", Title:="Checking File Existance!")
If AnswerM = "yes" Then
Z_Import_Mobile_2 'Calling another module code by its name
所以我可以直接从另一个 sheet 调用 MobileF Label 吗? 因为调用子例程标签将从一开始就调用完整代码,这不是 diresed
Goto
并不是真正好的流量控制方法:我们有很多更好的选择。关于 Goto
在错误处理之外唯一需要的是跳出多个嵌套循环。建议您重组代码以使用常规流程控制 (if/then) 并将需要从多个位置调用的任何代码分解为独立方法(子或函数)
If MsgBox("Do You Have a file to be uploaded?", _
vbQuestion + vbYesNo, "Checking File") = vbYes Then
Z_Import_Package_2 'Calling another module code by its name
Dim UploadedP As String
UploadedP = "Selected"
MobileF 'call MobileF
Else
UploadedP = "Skipped"
Dim LastRowCP As Long
LastRowCP = Ssheet4.Cells(Rows.Count, "C").End(xlUp).Offset(1).Row
Ssheet4.Range("C3:C" & LastRowCP).Copy Destination:=DestShtBPS.Cells(LR_DestShtB, "C")
'...
'...
将 MobileF 移至独立 Sub:
Sub MobileF()
If MsgBox("Do You Have another File to be uploaded?", _
vbQuestion + vbYesNo, _
"Checking File Existance!") = vbYes Then
Z_Import_Mobile_2
End If
End Sub