+ Reply to Thread
Results 1 to 1 of 1

How to show console messages during runtime in Excel VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Post How to show console messages during runtime in Excel VBA

    Hi Everyone,

    I am facing 2 issues while showing the console during run-time to display messages:

    1. The console I have chosen is a text box (named OutputBox) which is overlapped with the UserForm (which I am using). On click of a command button on UserForm, I want the OutputBox to be active and the UserForm should be gone. And this OutputBox should display run-time messages. Now the issue is when I am clicking the command button in UserForm, it activates the OutputBox but the UserForm still remains visible which makes the console messages display very bad.

    2. The second issue I am facing is that when the OutputBox displays run-time messages, it does not move to next line even though I have used vbCrLf in the code. It continues to print in the same line causing the messages to be unreadable.

    Can anyone please help me resolving this issue. I have given the code snippet below for reference.

    The code snippet which I am using is:

    Private Sub OutputToScreen(strOutputScreen As String)
    
    Dim WAIT As Double
    
    OutputBox.Value = strOutputScreen & vbCrLf & OutputBox.Value
    Form.Repaint
    WAIT = Timer
    While Timer < WAIT + 0.01
       DoEvents  'do nothing
    Wend
    
    End Sub
    
    Private Sub ExtractAgeData_Click()
    
    Dim ret, age_date As Variant
    Dim valDate_Start, valDate_End As Date
    Dim strADDMAP As String
    Dim valLoadDataToMainframe, valLoadToADABAS, valLoadToADABASIAM, valLoadToSysTest As Boolean
    Dim PTCABSTranslate As Variant
    
    On Error GoTo DAOEXISTS
        Application.References.AddFromFile ("C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll")
        Err.Clear
    DAOEXISTS:
        Resume Next
        
    OutputBox.Value = ""
    OutputBox.Visible = True
    Form.Repaint
    
    valLoadDataToMainframe = LoadDataToMainframe.Value
    PTCABSTranslate = AddressMapCheck.Value
    strADDMAP = AddressMapReference.Value
    
    If valLoadDataToMainframe = True Then
        If IsNull(mf_username.Value) Or Trim((mf_username.Value)) = "" Or IsNull(mf_password.Value) Then
            ret = MsgBox("Error - username/password must be input", vbOKOnly)
            OutputBox.Visible = False
            Exit Sub
        Else
            OutputToScreen ("Data will be loaded to Mainframe.......")
        End If
    Else
            OutputToScreen ("Data will NOT be loaded to Mainframe.......")
    End If
    
    If PTCABSTranslate = True Then
        If Trim(strADDMAP) = "" Then
            ret = MsgBox("Error - Address Map Reference must be input if the Use Address Maps is checked", vbOKOnly)
            OutputBox.Visible = False
            Exit Sub
        End If
        OutputToScreen ("PTCABS translation activated - using mapping " & strADDMAP & ".......")
    Else
        OutputToScreen ("PTCABS translation deactivated.......")
    End If
    
    age_date = BaseAgeDate.Value
    If IsNull(age_date) Or Trim(age_date) = "" Then
        age_date = Date
    End If
        
    OutputBox.SetFocus
    OutputToScreen ("Using " & age_date & " as base date for ageing.......")
    
    valLoadDataToMainframe = LoadDataToMainframe.Value
    
    If IsNull(LoadToSystest) Then
        valLoadToSysTest = False
    Else
        valLoadToSysTest = LoadToSystest.Value
    End If
    
    ' ================================================================
    ' Determine if the addresses are to be translated using the address
    ' mapping and if so, what address mapping reference to use.
    ' ================================================================
        If AddressMapCheck.Value = 0 Then
            PTCABSTranslate = False
        Else
            PTCABSTranslate = True
        End If
    
        If IsNull(AddressMapReference.Value) Then
            strADDMAP = ""
        Else
            strADDMAP = AddressMapReference.Value
        End If
            
    valDate_Start = Now()
    
    
    OutputToScreen ("Extracting data from database - please wait.......")
    
    '==================================================================
    ' Set output location for extracted data files and create directory
    '==================================================================
        OutputLocationName = ActiveWorkbook.Path & "DATALOAD-" & Replace(Replace(Replace(valDate_Start, "/", "-"), " ", "-"), ":", "-") & "\"
        MkDir OutputLocationName
    
    End Sub
    Last edited by Leith Ross; 05-25-2013 at 09:58 PM. Reason: Added Code Tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1