Vb.net 脚本在特定时间运行宏,excel以不可见模式运行

Vb.net 脚本在特定时间运行宏,excel以不可见模式运行,vb.net,Vb.net,'此代码位于工作簿的模块内。 子注释\电子邮件\ Excel\单元格2() Application.WindowState=xlNormal 作为对象的会话 作为对象的数据库 作为对象的Dim NUIWorkSpace 作为对象的Dim-NDoc 作为对象的Dim NUIdoc Dim WordApp作为对象 模糊主题为字符串 作为字符串的Dim dd 作为字符串的Dim stAttachment Dim ObaAttachment作为对象,EmbeddeObject作为对象 Const嵌入附件

'此代码位于工作簿的模块内。
子注释\电子邮件\ Excel\单元格2() Application.WindowState=xlNormal 作为对象的会话 作为对象的数据库 作为对象的Dim NUIWorkSpace 作为对象的Dim-NDoc 作为对象的Dim NUIdoc Dim WordApp作为对象 模糊主题为字符串 作为字符串的Dim dd 作为字符串的Dim stAttachment Dim ObaAttachment作为对象,EmbeddeObject作为对象 Const嵌入附件长度=1454 将Wb设置为工作簿 将第一个单元格设置为范围,将最后一个单元格设置为范围 尺寸CC(1) CC(1)=”yyy@itc.in"


1) 这似乎是VBA代码,而不是VB.NET代码。2) 请更好地格式化您的代码。3) 您想在Windows启动时还是在特定时间运行它?4) 我不知道在不运行Excel的情况下如何运行Excel。5) 请编辑您的问题以包含该问题,而不是使用问题的标题。您好,欢迎使用Stack Overflow,这只是我发送给新成员的一条消息,以帮助解决一些问题。新用户的学习曲线并不陡峭,但了解如何使用堆栈并不总是显而易见的。请花几分钟时间看看这里,看看这里也很重要。。此外,如果答案对您有效,请单击答案左侧的勾号,以便将问题标记为已回答,从而确保发布该问题的人获得声誉。干杯。没有启动Excel,您无法运行Excel VBA或自动运行Excel。非常感谢您的建议Andrew、Ken和David。由于我是新加入社区的,我将努力改进您提到的要点。再次感谢你。。
    If bIsBookOpen("Daily Beetle Count Report - MMGR.xlsx") = True Then
    Set Wb = Workbooks("Daily Beetle Count Report - MMGR.xlsx")
    Else
    Workbooks.Open ("B:\Sangeet\Daily Beetle Count Report - MMGR.xlsx")
    Set Wb = Workbooks("Daily Beetle Count Report - MMGR.xlsx")
    End If

    Set NSession = CreateObject("Notes.NotesSession")

    'Next line only works with 5.x and above. Replace password with your password



    subject = "HOT SPOTS Infestation " & Now
    Debug.Print subject


    Set NUIWorkSpace = CreateObject("Notes.NotesUIWorkspace")
    Set NDatabase = NSession.GetDatabase("", "")
    If Not NDatabase.IsOpen Then NDatabase.OPENMAIL

    'Create a new Lotus Notes document

    Set NDoc = NDatabase.CreateDocument
     stAttachment = ActiveWorkbook.FullName
     Set obAttachment = NDoc.CreateRichTextItem("stAttachment")
     Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)

    With NDoc
        .SendTo = "xxx@itc.in"              'CHANGE RECIPIENT EMAIL ADDRESS
        .CopyTo = ""
        .subject = subject

        'Email body text, including marker text which will be replaced by the Excel cells

        .body = "Dear All," & vbLf & vbLf & "Please find the Hotspot areas" & vbLf & vbLf & _
            "**PASTE HERE**" & vbLf & vbLf & vbLf & vbLf & _
            "Auto Generated Mail. Please Donot Reply."

        .Save True, False
    End With

    'Edit the just-created document to copy and paste the Excel cells into it via Word

    Set NUIdoc = NUIWorkSpace.EDITDocument(True, NDoc)
    With NUIdoc

        'Find the marker text in the Body item

        .GotoField ("Body")
        .FINDSTRING "**PASTE HERE**"
        '.DESELECTALL 'Uncomment to leave the marker text in place (cells are inserted immediately before)

        'Copy Excel cells to clipboard
        Wb.Sheets("HOT SPOT").Activate
        Sheets("HOT SPOT").Range("v2:w21").Copy                  'CHANGE SHEET AND RANGE TO BE COPIED AND PASTED

        'Create a temporary Word Document

        Set WordApp = CreateObject("Word.Application")
        WordApp.Visible = False                                 'True to aid debugging
        WordApp.Documents.Add

        'Paste into Word document and copy to clipboard

        With WordApp.Selection
            .PasteSpecial DataType:=10      'Enum WdPasteDataType: 10 = HTML; 2 = Text; 1 = RTF
            .WholeStory
            .Copy
        End With


        'Paste from clipboard (Word) to Lotus Notes document

        .Paste
        Application.CutCopyMode = False

        WordApp.Quit SaveChanges:=False
        Set WordApp = Nothing

        .Send


        .Close




    End With

    Set NSession = Nothing
    If bIsBookOpen("Daily Beetle Count Report - MMGR.xlsx") Then
    Workbooks("Daily Beetle Count Report - MMGR.xlsx").Close SaveChanges:=False
    Else
    End If




End Sub
Function bIsBookOpen(ByRef szBookName As String) As Boolean
    On Error Resume Next
    bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function