.FINDSTRING Lotus Notes VBA

时间:2016-09-15 12:04:58

标签: excel vba excel-vba lotus-notes

所以我正在使用Excel为我做一些例程,每次哀悼时都会发送一封电子邮件,其中包含例程从SAP中提取的数据。该数据包括应对2个图像和图形。

问题是,当我没有记录笔记时,宏运行顺利,但是当它已经打开时,“.FINDSTRING”找不到我插入的特定文本来粘贴图像。

我不知道为什么,我猜我需要一个命令来选择莲花并将它变为活动状态,这样才能使用findtring,但我不知道该怎么办。

这是编码的一部分:

'________________________________________________________________________
    Windows(FileHoje).Activate
        Columns("A:N").Select
        Range("A2").Activate
        Selection.ColumnWidth = 10
        Columns("G:G").Select
        Selection.ColumnWidth = 2.14
        Columns("C:C").EntireColumn.AutoFit
        Columns("K:K").EntireColumn.AutoFit
    '________________________________________________________________________
    Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

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

    .GotoField ("Body")
    .FINDSTRING "**1**"

    Windows(wb).Activate
        Sheets("Indicadores").Select
    '    ActiveSheet.PivotTables("Tabela dinâmica1").PivotFields("Semana").CurrentPage = Range("AV23").Value
        ActiveSheet.Shapes("Grupo 3").Select
        ActiveWindow.WindowState = xlNormal
        ActiveWindow.WindowState = xlMaximized
        Selection.Copy

    .Paste
    Application.CutCopyMode = False
    '________________________________________________________________________

    .GotoField ("Body")
    .FINDSTRING "**2**"

    Windows(FileHoje).Activate
    Dim LR As Integer
    LR = Range("H" & Rows.Count).End(xlUp).row
    Range("H1:N" & LR).Select
    Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

    .Paste
    Application.CutCopyMode = False


    '________________________________________________________________________
    .GotoField ("Body")
    .FINDSTRING "**3**"

    Windows(FileHoje).Activate
    Dim LW As Integer
    LW = Range("A" & Rows.Count).End(xlUp).row
    Range("A1:F" & LW).Select
    Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

    .Paste
    Application.CutCopyMode = False

    '________________________________________________________________________

    Windows(FileHoje).Activate
        Range("A9").Select
        Range("A2:N60000").Select
        Selection.Interior.ColorIndex = 2
        Range("O1").Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Interior.ColorIndex = 15
        Range("A2").Select
    Workbooks(FileHoje).Close SaveChanges:=True
    '________________________________________________________________________

            If attachmentFile <> "" Then
                If Dir(attachmentFile) <> "" Then
                    Set Attachment = .Document.CreateRichTextItem("Attachment")
                    .InsertText String(2, vbLf) & "File attached: " & Mid(attachmentFile, InStrRev(attachmentFile, "\") + 1)
                    Attachment.EmbedObject EMBED_ATTACHMENT, "", attachmentFile
                Else
                    MsgBox "Arquivo" & attachmentFile & " Não encontrado, não foi adicionado em anexo."
                End If
            End If
    '________________________________________________________________________
    .Send
    .Close
    End With


    Set NSession = Nothing

    Kill attachmentFile

     Application.DisplayAlerts = True
        Application.ScreenUpdating = True

    End Sub

1 个答案:

答案 0 :(得分:1)

此处的问题:如果Notes-客户端已打开,则使用“EditDocument”不会将窗口焦点更改为Notes-客户端。你必须自己做。

在我的一个项目中,我这样做了:

Set objWshShell = CreateObject("WScript.Shell")
objWshShell.AppActivate "Lotus Notes"
objWshShell.AppActivate "IBM Lotus Notes"
objWshShell.AppActivate "IBM Lotus Notes "
objWshShell.AppActivate "IBM Notes "

AppActivate将打开的应用程序的标题与给定的字符串匹配,如果没有匹配的应用程序,那么它什么都不做......