简体   繁体   English

如何从其中写入了单词Text的单元格中返回Excel VBA中“ Text”的等价物?

[英]How to return the equivalent of “Text” in Excel VBA from a cell that has the word Text written in it?

I'm trying to use VBA to send a PDF copy of a worksheet. 我正在尝试使用VBA发送工作表的PDF副本。 Everything works when my code looks like this: 当我的代码如下时,一切正常:

With OutlookMail
.To = "email_address@email.com"
.CC = ""
.BCC = ""
.Subject = "No Subject"
.Body = ""
.Attachments.Add FileName
.Send
End With

But I want to replace the email address in .To to an email address that has been written into the active worksheet within a cell that is formatted as text. 但我要替换的电子邮件地址.To到已经被格式化为文本的单元格中写入到活动工作表的电子邮件地址。 What I've tried is this: 我试过的是:

With OutlookMail
    .To = Range("K4").Text
    .CC = ""
    .BCC = ""
    .Subject = "No Subject"
    .Body = ""
    .Attachments.Add FileName
    .Send
    End With

Which I think should work but for some reason it doesn't. 我认为应该起作用,但由于某种原因却不起作用。 The cell is merged from K4 to N4 but when in a worksheet if I try =K4 it returns what is in the entire cell so I think this should be okay. 该单元格从K4合并到N4,但是在工作表中,如果我尝试=K4它将返回整个单元格中的内容,因此我认为应该没问题。 I'm sure this is a very easy question but I've tried looking things up and tried using CStr(Range("K4").Text) instead but no luck. 我确定这是一个非常简单的问题,但是我尝试查找内容并尝试使用CStr(Range("K4").Text)代替,但是没有运气。 Any suggestions? 有什么建议么?

使用Sheets("SheetName").Range("K4").Value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM