RAJESH1960
Banned for repeated rules violations
- Joined
- Mar 26, 2020
- Messages
- 2,313
- Office Version
- 2019
- Platform
- Windows
Hello Experts
I am trying to fit 2 MsgBox in one code, but it should display one only depending on the conditions in the code.
Right now the code runs and displays MsgBox ("File saved on Desktop as Master.XML.") even if there is no data.
I want to add just one line of code in the beginning.
If, in sheet MasterData cell B2 is Blank and when I press the button macro, the MsgBox should display “All Ledgers Available.” and stop from running the rest of the code.
Else, the code should continue to run and on completion, the MsgBox should display “File saved on Desktop as Master.XML.”.
I am trying to fit 2 MsgBox in one code, but it should display one only depending on the conditions in the code.
Right now the code runs and displays MsgBox ("File saved on Desktop as Master.XML.") even if there is no data.
I want to add just one line of code in the beginning.
If, in sheet MasterData cell B2 is Blank and when I press the button macro, the MsgBox should display “All Ledgers Available.” and stop from running the rest of the code.
Else, the code should continue to run and on completion, the MsgBox should display “File saved on Desktop as Master.XML.”.
Rich (BB code):
Option Explicit
Sub GenerateMasterXML()
'solved by JohnnyL
'
Dim LastColumnNumberInRow As Long
Dim x As Long
Dim xmlFile As Object
Dim LastColumnLetterSheetImportMasters As String
Dim strData As String
Dim strTempFile As String
'
x = Sheets("MasterData").Range("B2:B" & Sheets("MasterData").Range("B" & Rows.Count).End(xlUp).Row).Rows.Count ' Get count of rows to write to file
'
LastColumnNumberInRow = Sheets("ImportMasters").Cells(2, Sheets("ImportMasters").Columns.Count).End(xlToLeft).Column ' Get last column number in row
'
LastColumnLetterSheetImportMasters = Split(Cells(1, (Sheets("ImportMasters").Cells.Find("*", , xlFormulas, _
, xlByColumns, xlPrevious).Column)).Address, "$")(1) ' Get last column letter used in Sheets("ImportMasters")
'
Sheets("ImportMasters").Range("A2:" & LastColumnLetterSheetImportMasters & x + 1).FillDown ' Create range needed to copy
'
Sheets("ImportMasters").Range("A2").Resize(x, LastColumnNumberInRow).Copy
'
strData = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("Text") ' Save contents into strData
'
strTempFile = "C:\Users\" & Environ("username") & "\Desktop\Master.xml"
CreateObject("Scripting.FileSystemObject").CreateTextFile(strTempFile, True).Write strData ' Write the data to file
'
Application.CutCopyMode = False
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
MsgBox ("File saved on Desktop as Master.XML.")
End Sub