Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Display semicolor and newline in excel vba

  Asked By: Adelisa    Date: Dec 09    Category: MS Office    Views: 943
  

Display the sentences in textbox.

Example:

The machine's IP address is "10.12.13.24".
I love this IP.

Sample code Code:
-------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//* Show the sentences in the textbox *//
Private Sub cmdShow_Click()

Dim shtDVD As Worksheet
Dim strName As String

Set shtDVD = Application.ActiveWorkbook.Worksheets(1)

txtShow.Text = "The machine's IP address is "10.12.13.24"." &
vbNewLine & vbNewLine & "I love this IP."

End Sub
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Result:
-----------

(i) Got Error. If I replaced the "10.12.12.24" to 10.12.13.24 then it
is ok....May I know how can I display "10.12.13.24" instead of
10.12.13.24.

(ii) May I know how can I display my sentences as above without the
vbnewline because if I'm using vbnewline the code will proceed long
and messy:-
May I write my code as below?
*****************************************************************
Private Sub cmdShow_Click()

Dim shtDVD As Worksheet
Dim strName As String
Set shtDVD = Application.ActiveWorkbook.Worksheets(1)

txtShow.Text = "The machine's IP address is "10.12.13.24"."
txtShow.Text = "I love this IP."

End Sub

Share: 

 

1 Answer Found

 
Answer #1    Answered By: William Bouchard     Answered On: Dec 09

First: Displaying "10.12.13.24"
Remember you're using quotes (") to delimit the string.
that is kind-of like opening and closing parenths "()"
the first indicates the beginning of the string:
txtShow.Text = "
the second occurence indicates the end  of the string:
txtShow.Text = "The machine's IP address  is "
the compiler gets confused when trying to evaluate the data following
the closing parenthesis:
txtShow.Text = "The machine's IP address is "10.12.13.24
To include "embedded" quotes, use two:
txtShow.Text = "The machine's IP address is ""10.12.13.24""."

Next:
You're not going to get away with including the vbnewline in some manner.
You COULD save the double-newline as:
DL = vbnewline & vbnewline

Next, you could save the text  in a string variable:
MsgStr = "The machine's IP address is """ & IPAddr & ""."
MsgStr = MsgStr & DL & "I love this IP."

txtShow.Text = MsgStr

but calling txtshow.txt twice will result in two userforms being launched,
not
concatenating into one.

 
Didn't find what you were looking for? Find more on Display semicolor and newline in excel vba Or get search suggestion and latest updates.




Tagged: