In VBA how can I open a workbook minimised
- User
In VBA how can I open a workbook minimised
- Assistant
To open a workbook minimized in VBA, you can use the
Application.Visibleproperty. Here's an example code snippet that demonstrates how to open a workbook minimized:vbSub OpenWorkbookMinimized() Dim wb As Workbook Set wb = Workbooks.Open("C:\Path\to\your\workbook.xlsx") Application.Visible = False ' Hides the current workbook wb.Windows(1).WindowState = xlMinimized ' Minimizes the newly opened workbook ' Restore visibility Application.Visible = True End SubIn this code,
Workbooks.Openmethod is used to open the workbook at the specified path. Then,Application.Visible = Falsehides the currently active workbook, making it invisible. After that,wb.Windows(1).WindowState = xlMinimizedsets the WindowState property of the newly opened workbook's window to "Minimized". Finally,Application.Visible = Truerestores the visibility of the original workbook. - User
In this VBA event, then how will I open 'Service Providers History' minimised: Sub HistoryToNotepad() Dim sourceWorkbook As Workbook Dim destinationWorkbook As Workbook Dim sourceWorksheet As Worksheet Dim destinationWorksheet As Worksheet Dim path As String, fileName As String Dim lastRow As Long Dim i As Long path = "G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS" fileName = "Service Providers History.xlsx" Set sourceWorkbook = ThisWorkbook Set destinationWorkbook = Workbooks.Open(path & fileName) Dim activeSheetName As String activeSheetName = sourceWorkbook.ActiveSheet.Name Set sourceWorksheet = sourceWorkbook.ActiveSheet Set destinationWorksheet = destinationWorkbook.Sheets(activeSheetName) lastRow = destinationWorksheet.Cells(destinationWorksheet.Rows.Count, "J").End(xlUp).Row Shell "notepad.exe", vbNormalFocus Application.Wait Now + TimeValue("00:00:01") For i = 5 To lastRow Dim text As String text = destinationWorksheet.Range("I" & i).Value & " " & destinationWorksheet.Range("J" & i).Value SendKeys text SendKeys vbCrLf Next i SendKeys "^{HOME}" destinationWorkbook.Close False Set destinationWorksheet = Nothing Set destinationWorkbook = Nothing Set sourceWorksheet = Nothing Set sourceWorkbook = Nothing End Sub
- Assistant
To open the 'Service Providers History' workbook minimized in the
HistoryToNotepadevent, you can modify the code by adding the linedestinationWorkbook.Windows(1).WindowState = xlMinimizedafter opening the workbook. Here's the updated code:vb - User
In the VBA event below, I want to add the following conditions.
Do not include into the copy range if B = "Service" But where B = "Service" the date in H is less than Today, then include into the copy range
For i = 5 To lastRow If wscf.Cells(i, "I") = "" Then If copyRange Is Nothing Then Set copyRange = wscf.Range("J" & i) Else Set copyRange = Union(copyRange, wscf.Range("J" & i)) End If End If Next i
- Assistant
To add the conditions "Do not include into the copy range if B = 'Service'" and "Where B = 'Service' and the date in H is less than Today, then include into the copy range" in the given VBA event, you can modify the code as follows:
vbFor i = 5 To lastRow If wscf.Cells(i, "B") = "Service" Then If wscf.Cells(i, "H").Value < Date Then If copyRange Is Nothing Then Set copyRange = wscf.Range("J" & i) Else Set copyRange = Union(copyRange, wscf.Range("J" & i)) End If End If Else If wscf.Cells(i, "I") = "" Then If copyRange Is Nothing Then Set copyRange = wscf.Range("J" & i) Else Set copyRange = Union(copyRange, wscf.Range("J" & i)) End If End If End If Next i