2013-06-28 3 views
1

Je le code suivant:VBScript Impossible de trouver le fichier spécifié Server 2003

set app = CreateObject("Excel.Application") 
Set wb = app.Workbooks.Open("Y:\Billing_Common\autoemail\*.xls") 

set sh = wb.Sheets("Auto Email Script") 
row = 2 
name = "Customer" 
email = sh.Range("A" & row) 
subject = "Billing" 
the = "the" 
LastRow = sh.UsedRange.Rows.Count 

For r = row to LastRow 
    If App.WorkSheetFunction.CountA(sh.Rows(r)) <> 0 Then 
     SendMessage email, name, subject, TRUE, _ 
     NULL, "Y:\Billing_Common\autoemail\Script\energia-logo.gif", 143,393 
     row = row + 1 
     email = sh.Range("A" & row) 
    End if 
Next 
wb.close 
set wb = nothing 
set app = nothing 


Sub SendMessage(EmailAddress, DisplayName, Subject, DisplayMsg, AttachmentPath, ImagePath, ImageHeight, ImageWidth) 

    ' Create the Outlook session. 
    Set objOutlook = CreateObject("Outlook.Application") 

    template = FindTemplate() 

    ' Create the message. 
    Set objOutlookMsg = objOutlook.CreateItem(0) 

    With objOutlookMsg 
     ' Add the To recipient(s) to the message. 
     Set objOutlookRecip = .Recipients.Add(EmailAddress) 
     objOutlookRecip.resolve 
     objOutlookRecip.Type = 1 

    ' Set the Subject, Body, and Importance of the message. 
    .Subject = Subject 
    .bodyformat = 3 
    .Importance = 2 'High importance 

    body = Replace(template, "{First}", name) 
    body = Replace(body, "{the}", the) 

    if not isNull(ImagePath) then 
     if not ImagePath = "" then 
     .Attachments.add ImagePath 
     image = split(ImagePath,"\")(ubound(split(ImagePath,"\"))) 
     body = Replace(body, "{image}", "<img src='cid:" & image & _ 
     "'" & " height=" & ImageHeight &" width=" & ImageWidth & ">") 
     end if 
    else 
     body = Replace(body, "{image}", "") 
    end if 

    if not isNull(AttachMentPath) then 
     .Attachments.add AttachmentPath 
    end if 

    .HTMLBody = body 
     .Save 
     .Send 
    End With 
    Set objOutlook = Nothing 
End Sub 

Function FindTemplate() 
    Set OL = GetObject("", "Outlook.Application") 
    set Drafts = OL.GetNamespace("MAPI").GetDefaultFolder(16) 
    Set oItems = Drafts.Items 

    For Each Draft In oItems 
     If Draft.subject = "Template" Then 
      FindTemplate = Draft.HTMLBody 
      Exit Function 
     End If 
    Next 
End Function 

Il fonctionne très bien quand s'enfuir ma machine locale, mais lorsqu'il est exécuté hors serveur Windows, il jette une erreur sur la ligne:

Set wb = app.Workbooks.Open("Y:\Billing_Common\autoemail\*.xls") 

Dire qu'il ne peut pas trouver le fichier spécifié, le serveur a office 2003 sur elle et je l'ai manqué d'idées sur la raison pour laquelle il ne fonctionne pas.

Toute aide serait grandement appréciée!

Merci.

+0

est le lecteur 'Y:' mappé sur le serveur? –

+0

Oui, j'ai vérifié les noms, en décrivant tout si confus que cela ne marchera pas sur le serveur. Je pensais qu'il n'était pas compatible avec 2003 comme je l'ai 2007 sur mon PC local –

+0

peut-être 2003 ne supporte pas le joker dans votre chemin –

Répondre

2

La méthode Open d'Office 2003 ne prend probablement pas en charge les caractères génériques dans le chemin. Vous devrez énumérer les fichiers dans ce dossier:

Set app = CreateObject("Excel.Application") 
Set fso = CreateObject("Scripting.FileSystemObject") 

For Each f In fso.GetFolder("Y:\Billing_Common\autoemail").Files 
    If LCase(fso.GetExtensionName(f)) = "xls" Then 
    Set wb = app.Workbooks.Open(f.Path) 
    ... 
    wb.Close 
    End If 
Next 
+0

Merci beaucoup Ansgar, a travaillé après que j'ai recommandé le code! –

+0

Pour une alternative légèrement plus pratique pour l'énumération des fichiers, Office 2003 a toujours l'objet Application.FileSearch (http://msdn.microsoft.com/en-us/library/office/aa219847(v=office.11).aspx) . Cela a été abandonné dans Office 2007+ et partiellement remplacé par le support générique dans WorkBooks.Open et al. –

Questions connexes