Skip to content

Instantly share code, notes, and snippets.

@thoriqmacto
Last active January 11, 2021 15:12
Show Gist options
  • Select an option

  • Save thoriqmacto/86a7c1960091804243cf1c0293f43d67 to your computer and use it in GitHub Desktop.

Select an option

Save thoriqmacto/86a7c1960091804243cf1c0293f43d67 to your computer and use it in GitHub Desktop.
[VBA] Workbook operation including Create, Open and Close
'Create .xlsb file
Public Function RunWorkbookCreate(urlHistData As String, Optional CloseDirectly As Boolean = True) As Workbook
Dim newWbook As Workbook
Set newWbook = Workbooks.Add
newWbook.SaveAs Filename:=urlHistData, FileFormat:=50
Debug.Print "WbCREATE: " & newWbook.FullName
Set RunWorkbookCreate = newWbook
If CloseDirectly Then
Call FUNC.RunWorkbookClose(newWbook)
End If
End Function
'Closing ActiveWorkbook
Public Sub RunWorkbookClose(ActiveWbook As Workbook)
Debug.Print "WbCLOSE: " & ActiveWbook.FullName
ActiveWbook.Close True
End Sub
'Open Workbook based on fullpath
Public Function RunWorkbookOpen(urlHistData As String) As Workbook
Workbooks.Open urlHistData
Debug.Print "WbOPEN: " & urlHistData
Set RunWorkbookOpen = ActiveWorkbook
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment