英文:
How to concentrate Input into Url for href
问题
我非常新于VBA(和编程总体)并且正在寻求创建一个简单的宏,该宏将要求用户提供一些输入,并快速填充电子邮件。输入是我想要连接到电子邮件正文中静态URL末尾的ID号码。为了简洁起见,这是我到目前为止的代码:
Sub Release()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
Dim Obj1 As String
Obj1 = InputBox("输入ID1", "只输入数字")
If Obj1 <> ""
With objMsg
strEmailBody = "你好 ___" & "对象号码 #" & Obj1 & "<a href='http://....id=" & Obj1 & "'>(链接)</a>"
.HTMLBody = strEmailBody
一切似乎都表现得很好,除了链接,它是静态URL,不会按我所希望的方式与输入号码连接在一起。请提供建议!
我尝试更改引号和将整个URL更改为变量,但似乎无法在超链接中显示除所键入的字符串之外的内容。
英文:
I am very new to VBA (and programming in general) and I am looking to create a simple macro that will call for a few inputs from the user and flash-fill an email. The inputs being ID numbers that I want to concatenate to the end of a static URL and link in the body of the email. Skipping a bit for brevity, here's what I have so far:
`Sub Release()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
Dim Obj1 As String
Obj1 = InputBox("Enter ID1", "Input Number Only"
If Obj1 <> ""
With objMsg
strEmailBody = "Hello ___" & "Object #" & Obj1 & "<a href=""http://....id=""&Obj1>(link)</a>"
.HTMLBody = strEmailBody`
Everything seems to perform well except the link, which is the static URL and does not concatenate in the input number as I'd like it to. Please advise!
I tried changing around the quotation marks and changing the whole URL to a variable, but I cannot seem to get more than just the string as typed to appear in the hyperlink.
答案1
得分: 1
只需要正确拼接 VBA 中的字符串:
strEmailBody = "你好 ___" & "对象 #" & Obj1 & "<a href=" & Chr(34) & "http://....id=" & Obj1 & Chr(34) & ">(链接)</a>"
请注意,您可以使用 Chr 函数 来插入必要的双引号。
英文:
It seems you just need to concatenate strings in VBA correctly:
strEmailBody = "Hello ___" & "Object #" & Obj1 & "<a href=" & Chr(34) &"http://....id=" & Obj1 & Chr(34) & ">(link)</a>"
Note, you can use the Chr function for inserting double quotes where necessary.
答案2
得分: 0
strEmailBody = "Hello ___" & "Object #" & Obj1 & _
"<a href=""http://....id=" & Obj1 & """>(link)</a>"
或者更简单一点,使用单引号作为 href 属性值:
strEmailBody = "Hello ___" & "Object #" & Obj1 & _
"<a href='http://....id=" & Obj1 & "'>(link)</a>"
英文:
strEmailBody = "Hello ___" & "Object #" & Obj1 & _
"<a href=""http://....id=" & Obj1 & """>(link)</a>"
or a little simpler using single quotes for the href attribute value:
strEmailBody = "Hello ___" & "Object #" & Obj1 & _
"<a href='http://....id=" & Obj1 & "'>(link)</a>"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论