How to insert line break in message in VBA

pei

New Member
Joined
Feb 24, 2021
Messages
8
Office Version
  1. 2019
Platform
  1. Windows
Hello, this is my first time using VBA.

I am using Excel VBA to send messages via Whatsapp.
In my message in excel, there are paragraphs, however, when i try to send the message via whatapp there is no linebreak and I have to Alt+Enter manually.
Is there a code I can add into my VBA to create line breaks?
Please advise. Thank you.

VBA CODE:
Sub Customer()
On Error GoTo errorhandler:
mobilenumber = Selection.Value
Set myrange = Sheet1.Range("B:B")
rowno = Application.WorksheetFunction.Match(mobilenumber, myrange, 0)
Description = Sheet1.Cells(rowno, 3).Value
Rs = Sheet1.Cells(rowno, 4).Value
ActiveWorkbook.FollowHyperlink Address:="Open WhatsApp" & mobilenumber & "?text=" & Description & Rs & ""
End
errorhandler:
Err.Clear
MsgBox "Select Proper Mobile Number "
End Sub


Description:
Hello Gina, How is everything?

We did a video like this and targeted the right type of buyers on Facebook and the outcome was way better than just in guru. Not sure if this can help you but *ALL COSTS* are on us for this!

Maybe we can see if it can apply to your place as well if it's still for sale?
 
Last edited by a moderator:
I test on it. but I think your method for hyperlinking is wrong. Please work on it.
What exact what for hyperlinking? search on forums for exact hyperlink on other apps.
For others you can do one of this methods:
VBA Code:
Sub Customer()
Dim mobilenumber As Range, myRange As Range, rowno As Long, Description As String, Rs As String
On Error GoTo errorhandler:
Set mobilenumber = Selection
Set myRange = Sheet1.Range("E:E")
rowno = Application.WorksheetFunction.Match(mobilenumber, myRange, 0)
Description = Replace(Sheet1.Cells(rowno, 6), "#", vbNewLine)
Rs = Sheet1.Cells(rowno, 7).Value
On Error GoTo 0
ActiveWorkbook.FollowHyperlink Address:="Share on WhatsApp" & mobilenumber & "?text=" & Description & Rs & ""
End
If rowno < 1 Then
errorhandler:
Err.Clear
MsgBox "Select Proper Mobile Number "
End If
End Sub
VBA Code:
Sub Customer2()
Dim mobilenumber As Range, myRange As Range, rowno As Long, Description As String, Rs As String, CustName As String
On Error GoTo errorhandler:
Set mobilenumber = Selection
Set myRange = Sheet1.Range("E:E")
rowno = Application.WorksheetFunction.Match(mobilenumber, myRange, 0)
CustName = Sheet1.Cells(rowno, 4)
Description = "Hello" & CustName & ", How is everything?" & vbNewLine & vbNewLine & "Are you also facing issues for the" & vbNewLine & _
"listing of your property?" & vbNewLine & "No viewings or low offers?" & vbNewLine & "Before we found the perfect" _
& vbNewLine & "formula, we used to face these" & vbNewLine & "problems as well." & vbNewLine & vbNewLine & _
"Now, we did a video like this" & vbNewLine & "https://youtu.be/xc_9gdYqutg" & vbNewLine & "and targeted the right type of buyers on" _
& vbNewLine & "Facebook and the outcome was" & vbNewLine & "way better than just in guru." & vbNewLine & "Not sure if this can" _
& "help you but" & vbNewLine & "*ALL COSTS* are on us for this!" & vbNewLine & vbNewLine & "Perhaps we can see if it can be" & vbNewLine & _
"applied to your place if it's still" & vbNewLine & "for sale?" & vbNewLine & vbNewLine & "Gina (PA to Joel Li R044384D)" & vbNewLine & _
"www.home -link.sg"
Rs = Sheet1.Cells(rowno, 7).Value
On Error GoTo 0
ActiveWorkbook.FollowHyperlink Address:="Share on WhatsApp" & mobilenumber & "?text=" & Description & Rs & ""
End
If rowno < 1 Then
errorhandler:
Err.Clear
MsgBox "Select Proper Mobile Number "
End If
End Sub
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I test on it. but I think your method for hyperlinking is wrong. Please work on it.
What exact what for hyperlinking? search on forums for exact hyperlink on other apps.
For others you can do one of this methods:
VBA Code:
Sub Customer()
Dim mobilenumber As Range, myRange As Range, rowno As Long, Description As String, Rs As String
On Error GoTo errorhandler:
Set mobilenumber = Selection
Set myRange = Sheet1.Range("E:E")
rowno = Application.WorksheetFunction.Match(mobilenumber, myRange, 0)
Description = Replace(Sheet1.Cells(rowno, 6), "#", vbNewLine)
Rs = Sheet1.Cells(rowno, 7).Value
On Error GoTo 0
ActiveWorkbook.FollowHyperlink Address:="Share on WhatsApp" & mobilenumber & "?text=" & Description & Rs & ""
End
If rowno < 1 Then
errorhandler:
Err.Clear
MsgBox "Select Proper Mobile Number "
End If
End Sub
VBA Code:
Sub Customer2()
Dim mobilenumber As Range, myRange As Range, rowno As Long, Description As String, Rs As String, CustName As String
On Error GoTo errorhandler:
Set mobilenumber = Selection
Set myRange = Sheet1.Range("E:E")
rowno = Application.WorksheetFunction.Match(mobilenumber, myRange, 0)
CustName = Sheet1.Cells(rowno, 4)
Description = "Hello" & CustName & ", How is everything?" & vbNewLine & vbNewLine & "Are you also facing issues for the" & vbNewLine & _
"listing of your property?" & vbNewLine & "No viewings or low offers?" & vbNewLine & "Before we found the perfect" _
& vbNewLine & "formula, we used to face these" & vbNewLine & "problems as well." & vbNewLine & vbNewLine & _
"Now, we did a video like this" & vbNewLine & "https://youtu.be/xc_9gdYqutg" & vbNewLine & "and targeted the right type of buyers on" _
& vbNewLine & "Facebook and the outcome was" & vbNewLine & "way better than just in guru." & vbNewLine & "Not sure if this can" _
& "help you but" & vbNewLine & "*ALL COSTS* are on us for this!" & vbNewLine & vbNewLine & "Perhaps we can see if it can be" & vbNewLine & _
"applied to your place if it's still" & vbNewLine & "for sale?" & vbNewLine & vbNewLine & "Gina (PA to Joel Li R044384D)" & vbNewLine & _
"www.home -link.sg"
Rs = Sheet1.Cells(rowno, 7).Value
On Error GoTo 0
ActiveWorkbook.FollowHyperlink Address:="Share on WhatsApp" & mobilenumber & "?text=" & Description & Rs & ""
End
If rowno < 1 Then
errorhandler:
Err.Clear
MsgBox "Select Proper Mobile Number "
End If
End Sub
I just realised my hyperlink says "share on whatsapp" here. It changes when I paste it here.
It is actually ".h.t.t.p.s.:././.w.a...m.e./.6.5." (i added the dots as it changes the word)

I used these 2 options and change the hyperlink to ".h.t.t.p.s.:././.w.a...m.e./.6.5." but it still did not work. What else could be the reason?
 
Upvote 0
Please test only line of hyperlink o Whatsapp and see its work or no?
 
Upvote 0
Test this and see it worked or no:
VBA Code:
Sub Test2()
ActiveWorkbook.FollowHyperlink Address:="Share on WhatsApp" & "Hi. How are you?" & ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,390
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top