Last active
January 11, 2021 15:12
-
-
Save thoriqmacto/86a7c1960091804243cf1c0293f43d67 to your computer and use it in GitHub Desktop.
[VBA] Workbook operation including Create, Open and Close
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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