In the Worksheet_Activate event, is 'ColumnList Me.Range("B1")' the correct way to interact with 'Sub ColumnList(Target As Range)'
Private Sub Worksheet_Activate()
'PreviousSheetNum = ActiveSheet.index ' Store current sheet number
PreviousSheetNum = Me.index ' Store current sheet number
preventTrigger = False
Application.EnableEvents = False
If Me.Range("J30").Value <> "" Then
MsgBox "BACKUP OF PAGE REQUIRED", vbInformation, "BACKUP"
End If
Call Module30.CalculateSheet
Call Module28.TidyColumnK
Call Module29.BuildColumnK
Call Module21.FindEarliestServiceDate
Call Module20.RowRequest
Call Module23.SortTasksByDate
Call Module52.SectorList
ColumnList Me.Range("B1")
Application.EnableEvents = True
' Unlock Sheet
Me.Unprotect Password:="edit"
Me.Range("A5:A60").ClearContents
' Lock Sheet
Me.Protect Password:="edit"
End Sub
Sub ColumnList(Target As Range)
If Not Module9.sheetJobRequestActive Then Exit Sub
' Unlock Sheet
Me.Unprotect Password:="edit"
Dim rowValues As Range
Dim lastRow As Long
lastRow = Cells(Rows.count, "B").End(xlUp).row
Set rowValues = Me.Range("B" & lastRow & ":L" & lastRow)
Dim mValues As Variant
mValues = Application.Transpose(Me.Range("B" & lastRow & ":L" & lastRow))
Dim i As Long
For i = 1 To UBound(mValues, 1)
Me.Range("M" & i).Value = mValues(i, 1)
Next i
Me.Range("B" & Cells(Rows.count, "B").End(xlUp).row).Select
Me.Protect Password:="edit"
' Lock Sheet
Call Module14.TaskRequest
doubleClickFlag = False
End Sub
Assistant
Yes, 'ColumnList Me.Range("B1")' is the correct way to interact with 'Sub ColumnList(Target As Range)'. This code passes the range B1 in the active sheet as the target parameter to the ColumnList subroutine.
User
Assistant
In the modified VBA events, specifically in the RequestToContractorXYZ subroutine, you have made changes related to opening different Word documents based on conditions.
The issue might be related to the new logic of opening Word documents based on the value in cells (wsjrx.Range("J1").Value) and how it interacts with the ActiveWorda and ActiveWordb procedures.
It's important to ensure that the correct conditions are being met for opening the Word document and that the correct procedures are being called accordingly. Double-check the flow of the logic in the RequestToContractorXYZ subroutine and the conditions for calling ActiveWorda or ActiveWordb to ensure that the Word document opening functionality is triggered correctly.
Also, make sure to review the ActiveWorda and ActiveWordb procedures to see if there are any issues with how they are activating the correct worksheet or Word document. It's possible that the changes in the logic have affected the activation steps.
By carefully reviewing and debugging the logic flow and checking the conditions for opening Word documents, you should be able to identify and resolve the issue with the Word Macro document not opening as expected.
User
Can you please adjust the following functionality to the code below so that only one .docm opens
If .Range("M22").Value = "PEquote" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\TaskRequestpeq.docm"
If .Range("M12").Value = "JRquote" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\TaskRequest.docm"
If .Range("M12").Value <> "JRquote" AND If .Range("M22").Value <> "PEquote" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm"
Public Sub TaskRequest()
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
If Not Module9.sheetJobRequestActive Then Exit Sub ' if TRUE it allows the module to run
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
Dim wdApp As Object
Dim wdDoc As Object
Dim WsdShell As Object
Dim filePath As String
With ActiveSheet ' Assuming the relevant worksheet is active
If .Range("M12").Value = "JRquote" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\TaskRequest.docm"
Else
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm"
End If
.Range("M12").ClearContents
.Range("M22").ClearContents
End With
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(filePath)
wdApp.Visible = True
Set WsdShell = CreateObject("WScript.Shell")
WsdShell.AppActivate wdApp.Caption
Assistant
You can adjust the TaskRequest sub to open only one Word document based on the conditions specified. Here is the modified code with the adjusted functionality:
vb
I made some modifications to several VBA codes that work together and after my modifications I lost a particular functionality.
In my ORIGINAL VBA EVENTS the outcome opened a Word Macro document.
In my MODIFIED VBA EVENTS the Word Macro document did not open.
Can you detect what may have caused this.
ORIGINAL VBA EVENTS
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C2:E2")) Is Nothing Then Exit Sub
'ORIGINAL CODE FOR CHANGE IN F2 - WHEN ENTERING DATE SENT
'If Not Intersect(Target, Range("F2")) Is Nothing Then 'Currently in F2
'Call Complete
'Exit Sub
'End If
'NEW CODE FOR CHANGE IN F2 - WHEN ENTERING DATE SENT
If Not Intersect(Target, Range("F2")) Is Nothing Then 'If change made in F2
Application.EnableEvents = False
If Me.Range("A2").Value = "" Or Me.Range("B2").Value = "" Or Me.Range("C2").Value = "" Or Me.Range("D2").Value = "" Or Me.Range("E2").Value = "" Then 'If any of the cells from A2 to E2 are empty
Me.Range("F2").ClearContents 'Clear entry made in F2
MsgBox "Request Details Incomplete" & vbCrLf & "Complete and re-enter date"
Application.EnableEvents = True
Exit Sub
Else 'If all cells from A2 to E2 are not empty
Call RequestToContractorXYZ
Exit Sub
End If
End If
Sub RequestToContractorXYZ()
Dim wsjrx As Worksheet
Dim wscfx As Worksheet
Dim lastRow As Long
Set wsjrx = Worksheets("Job Request")
Set wscfx = Worksheets(Range("I2").Value)
' Unlock Sheet
wscfx.Unprotect Password:="edit"
Application.EnableEvents = False
Application.ScreenUpdating = False
lastRow = wscfx.Cells(wscfx.Rows.count, "B").End(xlUp).row + 1
'wscfx.Range("B" & lastRow).Value = "Remind"
wscfx.Range("B" & lastRow).Value = "Request"
wscfx.Range("C" & lastRow).Value = wsjrx.Range("F2").Value 'Date Sent
wscfx.Range("D" & lastRow).Value = wsjrx.Range("B2").Value 'Issue Type
wscfx.Range("F" & lastRow).Value = wsjrx.Range("C2").Value 'Location
wscfx.Range("J" & lastRow).Value = wsjrx.Range("E2").Value 'Summary of Request
wscfx.Range("L" & lastRow).Value = wsjrx.Range("D2").Value 'Details of Request
wscfx.Range("M12").Value = "" 'Clear PR No. in M12
' Lock Sheet
wscfx.Protect Password:="edit"
Application.ScreenUpdating = True
Application.EnableEvents = True
Call ActiveWord
End Sub
Public Sub ActiveWord()
Dim wsjrw As Worksheet
Dim wscfw As Worksheet
Set wsjrw = Worksheets("Job Request")
Set wscfw = Worksheets(Range("I2").Value)
Module9.sheetJobRequestActive = True 'THIS SET THE GLOBAL VARIABLE TO - TRUE - because the above code checks for TRUE the code runs
Application.Wait (Now + TimeValue("0:00:03"))
wscfw.Select
' Unlock Sheet
wsjrw.Unprotect Password:="edit"
Application.EnableEvents = False
Application.ScreenUpdating = False
wsjrw.Range("A2").ClearContents
wsjrw.Range("B2").ClearContents
wsjrw.Range("C2").ClearContents
wsjrw.Range("D2").ClearContents
wsjrw.Range("E2").ClearContents
wsjrw.Range("F2").ClearContents
wsjrw.Range("E7:E20").ClearContents
wsjrw.Range("E6").Calculate
' Lock Sheet
wsjrw.Protect Password:="edit"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Module.14
Public Sub TaskRequest()
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
If Not Module9.sheetJobRequestActive Then Exit Sub ' if TRUE it allows the module to run
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
Dim wdApp As Object
Dim wdDoc As Object
Dim WsdShell As Object
Dim filePath As String
With ActiveSheet ' Assuming the relevant worksheet is active
If .Range("M12").Value = "" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\TaskRequest.docm"
Else
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm"
End If
.Range("M12").ClearContents
End With
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(filePath)
wdApp.Visible = True
Set WsdShell = CreateObject("WScript.Shell")
WsdShell.AppActivate wdApp.Caption
End Sub
Public Sub PurchaseRequest()
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
If Not Module9.sheetJobRequestActive Then Exit Sub ' if TRUE it allows the module to run
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
code
Dim wdApp As Object
Dim wdDoc As Object
Dim WsdShell As Object
Set wdApp = CreateObject("Word.Application")
Dim filePath As String
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm"
Set wdDoc = wdApp.Documents.Open(filePath)
wdApp.Visible = True
Set WsdShell = CreateObject("WScript.Shell")
WsdShell.AppActivate wdApp.Caption
End Sub
MODIFIED VBA EVENTS
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C2:E2")) Is Nothing Then Exit Sub
'CHANGE IN F2 - WHEN ENTERING DATE SENT
If Not Intersect(Target, Range("F2")) Is Nothing Then 'If change made in F2
Application.EnableEvents = False
If Me.Range("A2").Value = "" Or Me.Range("B2").Value = "" Or Me.Range("C2").Value = "" Or Me.Range("D2").Value = "" Or Me.Range("E2").Value = "" Then 'If any of the cells from A2 to E2 are empty
Me.Range("F2").ClearContents 'Clear entry made in F2
MsgBox "Request Details Incomplete" & vbCrLf & "Complete and re-enter date"
Application.EnableEvents = True
Exit Sub
Else 'If all cells from A2 to E2 are not empty
Dim answer As Integer
answer = MsgBox("Request a Pre-Estimate Quote?", vbYesNo + vbQuestion)
If answer = vbYes Then
Me.Range("J1").Value = "PEQ"
Else
If answer = vbNo Then
Me.Range("J1").ClearContents
End If
End If
Call RequestToContractorXYZ
Exit Sub
End If
End If
Sub RequestToContractorXYZ()
Dim wsjrx As Worksheet
Dim wscfx As Worksheet
Dim lastRow As Long
Set wsjrx = Worksheets("Job Request")
Set wscfx = Worksheets(Range("I2").Value)
' Unlock Sheet
wscfx.Unprotect Password:="edit"
Application.EnableEvents = False
Application.ScreenUpdating = False
lastRow = wscfx.Cells(wscfx.Rows.count, "B").End(xlUp).row + 1
'wscfx.Range("B" & lastRow).Value = "Remind"
wscfx.Range("B" & lastRow).Value = "Request"
wscfx.Range("C" & lastRow).Value = wsjrx.Range("F2").Value 'Date Sent
wscfx.Range("D" & lastRow).Value = wsjrx.Range("B2").Value 'Issue Type
wscfx.Range("F" & lastRow).Value = wsjrx.Range("C2").Value 'Location
wscfx.Range("J" & lastRow).Value = wsjrx.Range("E2").Value 'Summary of Request
wscfx.Range("L" & lastRow).Value = wsjrx.Range("D2").Value 'Details of Request
wscfx.Range("M12").Value = "" 'Clear PR No. in M12
If wsjrx.Range("J1").Value = "PEQ" Then
Call ActiveWordb
wsjrx.Range("J1").ClearContents
Else
If wsjrx.Range("J1").Value <> "PEQ" Then
Call ActiveWorda
End If
End If
' Lock Sheet
wscfx.Protect Password:="edit"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Public Sub ActiveWorda() ' JOB REQUEST DOCUMENT ONLY
Dim wsjrw As Worksheet
Dim wscfw As Worksheet
Set wsjrw = Worksheets("Job Request")
Set wscfw = Worksheets(Range("I2").Value)
Module9.sheetJobRequestActive = True 'THIS SET THE GLOBAL VARIABLE TO - TRUE - because the above code checks for TRUE the code runs
Application.Wait (Now + TimeValue("0:00:02"))
'wscfw.Select
wscfw.Activate
' Unlock Sheet
wsjrw.Unprotect Password:="edit"
Application.EnableEvents = False
Application.ScreenUpdating = False
wsjrw.Range("A2").ClearContents
wsjrw.Range("B2").ClearContents
wsjrw.Range("C2").ClearContents
wsjrw.Range("D2").ClearContents
wsjrw.Range("E2").ClearContents
wsjrw.Range("F2").ClearContents
wsjrw.Range("E7:E20").ClearContents
wsjrw.Range("E6").Calculate
' Lock Sheet
wsjrw.Protect Password:="edit"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Public Sub ActiveWordb() ' JOB REQUEST DOCUMENT & PRE ESTIMATE QUOTE
Dim wsjrw As Worksheet
Dim wscfw As Worksheet
Set wsjrw = Worksheets("Job Request")
Set wscfw = Worksheets(Range("I2").Value)
wscfw.Unprotect Password:="edit" ' Unlock Sheet
wscfw.Range("M22").Value = "PEQ"
wscfw.Protect Password:="edit" ' Unlock Sheet
Module9.sheetJobRequestActive = True 'THIS SET THE GLOBAL VARIABLE TO - TRUE - because the above code checks for TRUE the code runs
Application.Wait (Now + TimeValue("0:00:02"))
'wscfw.Select
wscfw.Activate
' Unlock Sheet
wsjrw.Unprotect Password:="edit"
Application.EnableEvents = False
Application.ScreenUpdating = False
wsjrw.Range("A2").ClearContents
wsjrw.Range("B2").ClearContents
wsjrw.Range("C2").ClearContents
wsjrw.Range("D2").ClearContents
wsjrw.Range("E2").ClearContents
wsjrw.Range("F2").ClearContents
wsjrw.Range("E7:E20").ClearContents
wsjrw.Range("E6").Calculate
' Lock Sheet
wsjrw.Protect Password:="edit"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Module.14
Public Sub TaskRequest()
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
If Not Module9.sheetJobRequestActive Then Exit Sub ' if TRUE it allows the module to run
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
Dim wdApp As Object
Dim wdDoc As Object
Dim WsdShell As Object
Dim filePath As String
With ActiveSheet ' Assuming the relevant worksheet is active
If .Range("M22").Value = "PEQ" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PreEstimatedQuote.docm"
Application.Wait Now + TimeValue("00:00:01")
.Range("M22").ClearContents
ElseIf .Range("M12").Value = "" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\TaskRequest.docm"
Application.Wait Now + TimeValue("00:00:01")
.Range("M12").ClearContents
Else
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm"
End If
End With
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(filePath)
wdApp.Visible = True
Set WsdShell = CreateObject("WScript.Shell")
WsdShell.AppActivate wdApp.Caption
End Sub
Public Sub PurchaseRequest()
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
If Not Module9.sheetJobRequestActive Then Exit Sub ' if TRUE it allows the module to run
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
code
Dim wdApp As Object
Dim wdDoc As Object
Dim WsdShell As Object
Set wdApp = CreateObject("Word.Application")
Dim filePath As String
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm"
Set wdDoc = wdApp.Documents.Open(filePath)
wdApp.Visible = True
Set WsdShell = CreateObject("WScript.Shell")
WsdShell.AppActivate wdApp.Caption
End Sub
End Sub
Public Sub TaskRequest()
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
If Not Module9.sheetJobRequestActive Then Exit Sub ' if TRUE it allows the module to run
'USED TO OPEN WORD DOC FOR TASK REQUEST - DO NOT DELETE
Dim wdApp As Object
Dim wdDoc As Object
Dim WsdShell As Object
Dim filePath As String
With ActiveSheet ' Assuming the relevant worksheet is active
If .Range("M22").Value = "PEquote" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\TaskRequestpeq.docm"
ElseIf .Range("M12").Value = "JRquote" Then
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\TaskRequest.docm"
Else
filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm"
End If
.Range("M12").ClearContents
.Range("M22").ClearContents
End With
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(filePath)
wdApp.Visible = True
Set WsdShell = CreateObject("WScript.Shell")
WsdShell.AppActivate wdApp.Caption
End Sub
In this modified code, the TaskRequest sub checks the values in cells M12 and M22 to determine which Word document to open. If M22 is "PEquote", it will open "TaskRequestpeq.docm". If M12 is "JRquote", it will open "TaskRequest.docm". Otherwise, it will open "PurchaseRequest.docm".
After determining the file path based on the conditions, the code clears the contents of cells M12 and M22 (to avoid re-opening the same document on subsequent runs) and then proceeds to open the selected Word document.
Please replace your existing TaskRequest code with this adjusted version to achieve the desired functionality.