简体   繁体   English

从 Excel 中的不同工作表获取单元格值以在 VBA 中使用它?

[英]Get a cell value from a different worksheet in Excel to use it in VBA?

I'm using VBA macro in excel to transfer date to my mail but I want to use value of cells that are in a different sheet in the same workbook.我在 excel 中使用 VBA 宏将日期传输到我的邮件,但我想使用同一工作簿中不同工作表中的单元格的值。 How do I get them?我如何获得它们?

I tried this : Worksheets("sheet 6").Range("B27") but it didn't work.我试过这个: Worksheets("sheet 6").Range("B27")但它没有用。 Also tried Worksheets("Salaris").Range("B27") because "salaris" is the name of the sheet but it didnt work.还尝试了Worksheets("Salaris").Range("B27")因为 "salaris" 是工作表的名称,但它没有用。

VBA compile Syntaxerror VBA 编译语法错误

code代码

  'On Error Resume Next

    With OutMail
    .To = "" ' Either an email address or a cell value that contains an email address: ActiveSheet.Range("B11").Value
    .CC = ""
    .BCC = ""
    .Body = "Geachte heer, mevrouw," & vbNewLine & _
    " " & vbNewLine & _
    "De volgende kasbankopdrachten staan klaar in Kasweb onder rekeningnummer........ Ik verzoek u ze te valideren." & vbNewLine & _
    "Bijgaand ontvangt u het boedeloverzicht, tevens treft u hieronder de berekening van het nog te innen bewindvoerdersalaris en onkosten." & vbNewLine & _
    ActiveSheet.Range("C4").Value & Space(3) & ActiveSheet.Range("C3").Value & Space(10) & ActiveSheet.Range("C3").Value & Space(20) & ActiveSheet.Range("C27").Value & Space(5) & ActiveSheet.Range("B27").Value & vbNewLine & _
    ActiveSheet.Range("C4").Value & Space(3) & ActiveSheet.Range("C3").Value & Space(10) & ActiveSheet.Range("B2").Value & Space(15) & ActiveSheet.Range("C26").Value & Space(5) & ActiveSheet.Range("B26").Value & vbNewLine & _

    " " & vbNewLine & _

    "Salaris volgens vonnis (incl. 21% BTW)" & Space(14) & ThisWorkbook.Worksheets("Salaris").Cells("42, P").Value & vbNewLine & _
    vbEndLine & _

    .Subject = ActiveSheet.Range("C4").Value & Space(3) & ActiveSheet.Range("C5").Value & Space(3) & ActiveSheet.Range("C3").Value
    .Display
    .Attachments.Add PdfFile  ' 
End With
On Error GoTo 0


Set OutMail = Nothing
Set OutApp = Nothing
End Sub

尝试使用:

ThisWorkbook.Worksheets("Salaris").Cells(27,"B").Value

在VBA中,当一行没有完全完成而你去换行时,你需要写一个下划线“_”,你确定你在写“&”的每个&之后都这样做了吗?

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

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