Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3510

Re: VBA Save BEx workbook to pure Excel file after removing BEx references

$
0
0

' Here is the code...

' Purists will want to dimension all variables...

 

 

 

Sub RemoveBExSheetsAndCloseBExMenu()

 

  Dim saveAs_FileName As String

 

 

  Application.EnableEvents = False     ' Remove BEx overhead and speed up process

  Application.DisplayAlerts = False    ' Don't show delete and save confirmation messages

 

  For i = Sheets.Count To 1 Step -1    ' Must delete from the end otherwise index is broken

    If Sheets(i).Name = "BExRepositorySheet" Or _

       Sheets(i).Name = "SomeBWSheetName1" Or _

       Sheets(i).Name = "SomeBWSheetName2" Then

        Sheets(i).Visible = True

        Sheets(i).Delete

    End If

  Next

 

 

  '

  ' Show default filename and filepath and allow changing

  saveAs_FileName = selectFilename("FileWithBExRemoved.xlsm")

 

 

  '

  ' Actual saving of file

  If saveAs_FileName <> "" Then

     ActiveWorkbook.SaveAs saveAs_FileName   ' Saves only to the same extension as the active workbook

  End If

 

 

  '

  ' Remove command bars

  Call CommandBars("BEx Design Toolbox").Delete

  Call CommandBars("BEx Analysis Toolbox").Delete

  '

  ' Hide menu bar   (delete won't work)

  CommandBars("Worksheet Menu Bar").Controls("&BEx Analyzer").Visible = False

 

  ' Return to normal BEx environment... but no BEx

  Application.DisplayAlerts = True     ' Return to displaying messages

  Application.EnableEvents = True      ' Reactivate BEx buttons and functions (just for the sake of it)

 

 

End Sub

 

 

 

 

Private Function selectFilename(defaultFileName As String) As String

 

 

   Dim varResult As Variant

 

   If defaultFileName = "" Then defaultFileName = "FileWithBExRemoved.xlsm"

 

 

   selectFilename = ""

 

   varResult = Application.GetSaveAsFilename(Title:="Please choose file name and path", InitialFileName:=defaultFileName)

 

   If varResult <> False Then

      selectFilename = varResult

   End If

 

 

End Function


Viewing all articles
Browse latest Browse all 3510

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>