Msg Box Title

G

Gene Haines

Totally new to VBA. I have pasted a VBA code and was wondering how I ca
keep the MsgBox Title consistent throughout the VBA procedure. I hav
the following code but when the ans = vbno, the MsgBox Title i
Microsoft Excel and not Metals Inventory Database. any help would b
greatly appreciated.

Private Sub Workbook_Open()
If Worksheets("Sheet1").Range("F2").Value > 0 Then
Msg = "You owe a balance due to Virginia at this time!"
Msg = Msg & vbLf & vbLf
Msg = Msg & "Would you like to fufill that obligation"
Msg = Msg & " with an Funds Transfer?"
Title = "Metals Inventory Database"
Config = vbYesNo + vbQuestion
Ans = MsgBox(Msg, Config, Title)
If Ans = vbYes Then Workbooks.Open ("C:\Documents and Settings\M
Folder\My Documents\TestII.xlsx")
If Ans = vbNo Then MsgBox ("Then please do a Journal Voucher. Than
you.")
Else
MsgBox ("No Blance Owed")
End If
End Sub


Thank yo
 
W

Walter Briscoe

In message <[email protected]> of Sat, 2 Mar 2013
01:33:02 in microsoft.public.excel.newusers, Gene Haines <Gene.Haines.b7
(e-mail address removed)> writes
Totally new to VBA. I have pasted a VBA code and was wondering how I
can
keep the MsgBox Title consistent throughout the VBA procedure. I have
the following code but when the ans = vbno, the MsgBox Title is
Microsoft Excel and not Metals Inventory Database. any help would be
greatly appreciated.

The OP might like to adapt what I show below AS I have adapted what he
has written.

Option Explicit ' All modules should start so to avoid some bugs


Private Function MIDMsg(ByVal Msg As String, Optional ByVal Config As Long = 0) As Long
Const Title As String = "Metals Inventory Database"

MIDMsg = MsgBox(Msg, Config, Title)
End Function

Public Sub foo()
Dim Msg As String

If True Then
Msg = "You owe a balance due to Virginia at this time!" & _
vbLf & vbLf & _
"Would you like to fufill that obligation" & _
" with an Funds Transfer?"
' Brackets in call statements seem odd to me
If MIDMsg(Msg, vbYesNo + vbQuestion) = vbYes Then
' Use call if you really want to have brackets
Call Workbooks.Open("C:\Documents and Settings\MyFolder\My Documents\TestII.xlsx")
Else
' Or leave them out for textual economy.
MIDMsg "Then please do a Journal Voucher. Thank you."
End If
Else
' I have corrected a slip.
MIDMsg "No B[a]lance Owed"
End If

End Sub
Thank you

You're welcome. I found your problem entertaining.
N.B. my long lines may wrap in an unfriendly way.
 
G

Gene Haines

Walter said:
In message <[email protected]> of Sat, 2 Mar 2013
01:33:02 in microsoft.public.excel.newusers, Gene Haine
<Gene.Haines.b7
(e-mail address removed)> writes-
Totally new to VBA. I have pasted a VBA code and was wondering how I
can
keep the MsgBox Title consistent throughout the VBA procedure. I have
the following code but when the ans = vbno, the MsgBox Title is
Microsoft Excel and not Metals Inventory Database. any help would be
greatly appreciated.-

The OP might like to adapt what I show below AS I have adapted what he
has written.

Option Explicit ' All modules should start so to avoid some bugs


Private Function MIDMsg(ByVal Msg As String, Optional ByVal Config A
Long = 0) As Long
Const Title As String = "Metals Inventory Database"

MIDMsg = MsgBox(Msg, Config, Title)
End Function

Public Sub foo()
Dim Msg As String

If True Then
Msg = "You owe a balance due to Virginia at this time!" & _
vbLf & vbLf & _
"Would you like to fufill that obligation" & _
" with an Funds Transfer?"
' Brackets in call statements seem odd to me
If MIDMsg(Msg, vbYesNo + vbQuestion) = vbYes Then
' Use call if you really want to have brackets
Call Workbooks.Open("C:\Documents and Settings\MyFolder\M
Documents\TestII.xlsx")
Else
' Or leave them out for textual economy.
MIDMsg "Then please do a Journal Voucher. Thank you."
End If
Else
' I have corrected a slip.
MIDMsg "No B[a]lance Owed"
End If

End Sub
-
Thank you-

You're welcome. I found your problem entertaining.
N.B. my long lines may wrap in an unfriendly way.

Thank you Walter: I will set this up.

Regards

Gen
 
G

Gene Haines

Gene said:
Thank you Walter: I will set this up.

Regards

Gene

Walter: Forgive my lack of VBA experience, but I am not sure where to g
from here. I've pasted the code and can't figure out how to get oast th
Compile Error: Expected End Sub in the Private WorkBook-Open()

Option Explicit
Private Sub Workbook_Open()
If Worksheets("Sheet1").Range("F2").Value > 0 Then

Public Sub foo()
Dim Msg As String

Private Function MIDMsg(ByVal Msg As String, Optional ByVal Confi
As Long = 0) As Long
Const Title As String = "Metals Inventory Database"

MIDMsg = MsgBox(Msg, Config, Title)
End Function



If True Then
Msg = "You owe a balance due to Virginia at this time!" & _
vbLf & vbLf & _
"Would you like to fufill that obligation" & _
" with a Funds Transfer?"
' Brackets in call statements seem odd to me
If MIDMsg(Msg, vbYesNo + vbQuestion) = vbYes Then
' Use call if you really want to have brackets
Call Workbooks.Open("C:\Documents and Settings\My Folder\M
Documents\TestII.xlsx")
Else
' Or leave them out for textual economy.
MIDMsg "Then please do a Journal Voucher. Thank you."
End If
Else
' I have corrected a slip.
MIDMsg "No Balance Owed"
End If

End Su
 
W

Walter Briscoe

In message <[email protected]> of Sun, 3 Mar 2013
13:03:34 in microsoft.public.excel.newusers, Gene Haines <Gene.Haines.b7
(e-mail address removed)> writes
Walter: Forgive my lack of VBA experience, but I am not sure where to

I suggest you lack understanding rather than knowledge.
go
from here. I've pasted the code and can't figure out how to get oast

Pasting was not an appropriate operation.
You needed to merge the ideas in my code with your own.
Why did you throw away the indentation in my code?
It aids understanding.
the
Compile Error: Expected End Sub in the Private WorkBook-Open()

What did you do in response to that error, other than post?
Option Explicit
Private Sub Workbook_Open()
If Worksheets("Sheet1").Range("F2").Value > 0 Then

Public Sub foo()
Dim Msg As String

Private Function MIDMsg(ByVal Msg As String, Optional ByVal Config
As Long = 0) As Long
Const Title As String = "Metals Inventory Database"

MIDMsg = MsgBox(Msg, Config, Title)
End Function



If True Then
Msg = "You owe a balance due to Virginia at this time!" & _
vbLf & vbLf & _
"Would you like to fufill that obligation" & _
" with a Funds Transfer?"
' Brackets in call statements seem odd to me
If MIDMsg(Msg, vbYesNo + vbQuestion) = vbYes Then
' Use call if you really want to have brackets
Call Workbooks.Open("C:\Documents and Settings\My Folder\My
Documents\TestII.xlsx")
Else
' Or leave them out for textual economy.
MIDMsg "Then please do a Journal Voucher. Thank you."
End If
Else
' I have corrected a slip.
MIDMsg "No Balance Owed"
End If

End Sub


You might try a module like this.
Option Explicit

Private Function MIDMsg(ByVal Msg As String, _
Optional ByVal Config As Long = 0) As Long
Const Title As String = "Metals Inventory Database"

MIDMsg = MsgBox(Msg, Config, Title)
End Function

Private Sub Workbook_Open()
Const Msg As String = "You owe a balance to Virginia!" & _
vbLf & vbLf & _
"Would you like to fufill that obligation" & _
" with a Funds Transfer?"
Const fname As String = "C:\Documents and Settings\" & _
"MyFolder\My Documents\TestII.xlsx"

If Worksheets("Sheet1").Range("F2").Value > 0 Then
If MIDMsg(Msg, vbYesNo + vbQuestion) = vbYes Then
Workbooks.Open fname
Else
MIDMsg "Then please do a Journal Voucher. Thank you."
End If
Else
MIDMsg "No Balance Owed"
End If
End Sub

I have thrown away some of your text.
 
G

Gene Haines

Walter said:
In message <[email protected]> of Sun, 3 Mar 2013
13:03:34 in microsoft.public.excel.newusers, Gene Haine
<Gene.Haines.b7
(e-mail address removed)> writes-

I suggest you lack understanding rather than knowledge.
-

Pasting was not an appropriate operation.
You needed to merge the ideas in my code with your own.
Why did you throw away the indentation in my code?
It aids understanding.
-

What did you do in response to that error, other than post?
-


You might try a module like this.
Option Explicit

Private Function MIDMsg(ByVal Msg As String, _
Optional ByVal Config As Long = 0) As Long
Const Title As String = "Metals Inventory Database"

MIDMsg = MsgBox(Msg, Config, Title)
End Function

Private Sub Workbook_Open()
Const Msg As String = "You owe a balance to Virginia!" & _
vbLf & vbLf & _
"Would you like to fufill that obligation" & _
" with a Funds Transfer?"
Const fname As String = "C:\Documents and Settings\" & _
"MyFolder\My Documents\TestII.xlsx"

If Worksheets("Sheet1").Range("F2").Value > 0 Then
If MIDMsg(Msg, vbYesNo + vbQuestion) = vbYes Then
Workbooks.Open fname
Else
MIDMsg "Then please do a Journal Voucher. Thank you."
End If
Else
MIDMsg "No Balance Owed"
End If
End Sub

I have thrown away some of your text.

Walter: I actually tried to solve the problem myself believe it or not
I put in an Else If and then an End Sub and the code stopped, which
guess it should have. I cannot fully understand at this time exactly ho
the processes flow in VBA Code This is my first attempt in VBA. I a
looking for a user friendly VBA book to purchase and teach myself
Thanks for you input.

Regards

Gen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top