将输入集中到href的URL中。

huangapple go评论50阅读模式
英文:

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(&quot;Enter ID1&quot;, &quot;Input Number Only&quot;
If Obj1 &lt;&gt; &quot;&quot; 

With objMsg
strEmailBody = &quot;Hello ___&quot; &amp; &quot;Object #&quot; &amp; Obj1 &amp; &quot;&lt;a href=&quot;&quot;http://....id=&quot;&quot;&amp;Obj1&gt;(link)&lt;/a&gt;&quot;
.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 = &quot;Hello ___&quot; &amp; &quot;Object #&quot; &amp; Obj1 &amp; &quot;&lt;a href=&quot; &amp; Chr(34) &amp;&quot;http://....id=&quot; &amp; Obj1 &amp; Chr(34) &amp; &quot;&gt;(link)&lt;/a&gt;&quot;

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 = &quot;Hello ___&quot; &amp; &quot;Object #&quot; &amp; Obj1 &amp; _
               &quot;&lt;a href=&quot;&quot;http://....id=&quot; &amp; Obj1 &amp; &quot;&quot;&quot;&gt;(link)&lt;/a&gt;&quot;

or a little simpler using single quotes for the href attribute value:

strEmailBody = &quot;Hello ___&quot; &amp; &quot;Object #&quot; &amp; Obj1 &amp; _
               &quot;&lt;a href=&#39;http://....id=&quot; &amp; Obj1 &amp; &quot;&#39;&gt;(link)&lt;/a&gt;&quot;

huangapple
  • 本文由 发表于 2023年2月14日 04:45:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定