Double Quotes in MsgBox!

J

Joyce

Hi,

I'm trying to copy code from personal.xls to the active workbook. Here is
part of the code: I have noted where my problem line is. I know I'm not
using the & DQUOTE properly, but can't figure it out. I have line breaks to
make the dialog box more readable, BTW...

Sub Test()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character

Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ThisWorkbook")
Set CodeMod = VBComp.CodeModule
With CodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, "Private Sub Workbook_Open()"
LineNum = LineNum + 1
.InsertLines LineNum, "Application.DisplayAlerts = False"
LineNum = LineNum + 1
.InsertLines LineNum, "Dim oAction As Integer"
LineNum = LineNum + 1

***This is the line I'm having problems with**
.InsertLines LineNum, " oAction = MsgBox(Prompt:=" & DQUOTE &
"WILL YOU EDIT THE FILE?" & vbNewLine & vbNewLine & "Click 'YES' if opening
to EDIT" & vbNewLine & vbNewLine & "Click 'NO' if opening to VIEW or PRINT &
dquote & ", Buttons:=vbYesNo, Title:=" & dquote FILE OPEN:" & DQUOTE & ")"

LineNum = LineNum + 1

Thanks very much.
 
J

Jim Cone

Dim S as Long
S = MsgBox(prompt:="WILL YOU EDIT THE FILE?" & vbNewLine & vbNewLine & _
"Click 'YES' if opening to EDIT" & vbNewLine & vbNewLine & _
"Click 'NO' if opening to VIEW or PRINT", Buttons:=vbYesNo, Title:=" FILE OPEN:")
--
Jim Cone
Portland, Oregon USA



"Joyce" <[email protected]>
wrote in message
Hi,
I'm trying to copy code from personal.xls to the active workbook. Here is
part of the code: I have noted where my problem line is. I know I'm not
using the & DQUOTE properly, but can't figure it out. I have line breaks to
make the dialog box more readable, BTW...
-snip
***This is the line I'm having problems with**
.InsertLines LineNum, " oAction = MsgBox(Prompt:=" & DQUOTE &
"WILL YOU EDIT THE FILE?" & vbNewLine & vbNewLine & "Click 'YES' if opening
to EDIT" & vbNewLine & vbNewLine & "Click 'NO' if opening to VIEW or PRINT &
dquote & ", Buttons:=vbYesNo, Title:=" & dquote FILE OPEN:" & DQUOTE & ")"

LineNum = LineNum + 1

Thanks very much.
 
J

Joyce

Thanks for your help. I noticed another one I had forgotten, but was
reassured to know I was on the write path!



Paul E Collins said:
Joyce said:
[...]
"Click 'NO' if opening to VIEW or PRINT & dquote & ", Buttons:=vbYesNo,
[...]

You seem to have missed a double-quote mark after "PRINT", in order to close
the literal text and switch back to the use of the & concatenation operator.

Eq.
 
J

Joyce

I spoke too soon... Here is the updated code. It results in the first line
being copied into the active workbook -it ignores the rest, so I must again
be doing something wrong.

oAction = MsgBox(Prompt:="WILL YOU EDIT THE FILE?"

..InsertLines LineNum, " oAction = MsgBox(Prompt:=" & DQUOTE & "WILL YOU EDIT
THE FILE?" & DQUOTE & vbNewLine & vbNewLine & DQUOTE & "Click 'YES' if
opening to EDIT" & DQUOTE & vbNewLine & vbNewLine & DQUOTE & "Click 'NO' if
opening to VIEW or PRINT" & DQUOTE & ", Buttons:=vbYesNo, Title:=" & DQUOTE &
"FILE OPEN:" & DQUOTE & ")"

Thanks very much.

Paul E Collins said:
Joyce said:
[...]
"Click 'NO' if opening to VIEW or PRINT & dquote & ", Buttons:=vbYesNo,
[...]

You seem to have missed a double-quote mark after "PRINT", in order to close
the literal text and switch back to the use of the & concatenation operator.

Eq.
 
J

Jim Cone

And if you actually want to put all the text inside quote marks then...

Dim oAction
Dim DQUOTE As String
DQUOTE = Chr$(34)

oAction = MsgBox(Prompt:=DQUOTE & "WILL YOU EDIT THE FILE?" & _
DQUOTE & vbNewLine & vbNewLine & DQUOTE & _
"Click 'YES' if opening to EDIT" & DQUOTE & vbNewLine & _
vbNewLine & DQUOTE & "Click 'NO' if opening to VIEW or PRINT" & _
DQUOTE, Buttons:=vbYesNo, Title:=DQUOTE & "FILE OPEN:" & DQUOTE)
 

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

Top