2014-02-26 125 views
0

我的第一篇文章,但我一直潛伏了很長時間。我正在爲一家使用Outlook的VB的公司工作,以從自定義任務表單宏觀化他們所做的一切。嗯,我想能夠激活子,將加入到這一點:從預VBScript從Outlook創建文件/文件夾在網絡驅動器

  1. 我們的本地服務器/網絡驅動器上創建一個文件夾(其中每個人都有權限)
  2. 複製文件和文件夾做「模板」文件夾到新的目標
  3. 重命名新目錄中的文件與變量名

目前我在:

Dim  fso 
Dim  sourceFol 
Dim  DestFol 
Dim  variable1 
Dim  variable2 

Set fso = CreateObject("Scripting.FileSystemObject") 
If ClientCode = "1" Then 
    sourceFol = "\\S:\sourcepath" 
    DestFol = "\\S:\destination\"& variable1 &" - "& variable2            
    ElseIf ClientCode = "2" Then 
    sourceFol = "\\S:\sourcepath" 
    DestFol = "\\S:\destination\"& variable1 &" - "& variable2            
     ElseIf ClientCode = "3" Then 
     sourceFol = "\\S:\sourcepath" 
     DestFol = "\\S:\destination\"& variable1 &" - "& variable2   
End If 

If Error Then 
    WScript.Echo "Error: " & Err.Number 
    WScript.Echo "Source: " & Err.Source & "Description:" & Err.Description 
    Err.Clear 
    Else 
    'Cancel 
End If 

唯一的問題是,我沒有從這一點上得到什麼,沒有反應,沒有錯誤,沒有從我所看到的想法。看到這只是我名單上的第一名,我什麼都沒有得到,這是非常令人沮喪的。任何人有任何好的提示,指針或在這種情況下檢查的東西?謝謝。

+2

上的錯誤恢復刪除你的下一個並重新運行它。你不會在任何地方處理錯誤,這就是爲什麼你不知道它們是什麼。 –

+0

你的路徑應該看起來像'\\ Server \ sourcepath' –

+0

'Else If'是你的問題之一。 VB語言使用'ElseIf'代替。但我贊同Nathan。禁用'在錯誤恢復下一步'。這部分根本不需要。 – Bond

回答

0
Dim fso 
Dim clientcode 
Dim variable1 
Dim variable2 
Dim Folder 

ClientCode = Trim(Item.UserProperties("Client")) 

If ClientCode = "1" Then 
    folder = "R:\path"& variable1 &"-"& variable2 
    ElseIf ClientCode = "2" Then 
    folder = "R:\01 - CHA\"& variable1 &"-"& variable2 
     ElseIf ClientCode = "3" Then 
     folder = "R:\03 - REOR\"& variable1 &"-"& variable2 
End if 

Set fso = CreateObject("Scripting.FileSystemObject") 
    If Not fso.FolderExists(folder) Then 
     fso.CreateFolder (folder) 
     MsgBox "Folder Successfully Created and Named" 
    Else 
     MsgBox folder & " already exists!", vbExclamation, "Folder Exists" 
    End If 
0

這段代碼需要很長的路要走。但是這裏有一個代碼的修改,所以你可以得到輸出。

Dim  fso 
Dim  sourceFol 
Dim  DestFol 
Dim  variable1 
Dim  variable2 
Dim  result 

Set fso = CreateObject("Scripting.FileSystemObject") 
If ClientCode = "1" Then 
    sourceFol = "\\S:\sourcepath" 
    DestFol = "\\S:\destination\"& variable1 &" - "& variable2            
    result = "Succeeded in string set: 1" 
ElseIf ClientCode = "2" Then 
    sourceFol = "\\S:\sourcepath" 
    DestFol = "\\S:\destination\"& variable1 &" - "& variable2            
    result = "Succeeded in string set: 2" 
ElseIf ClientCode = "3" Then 
    sourceFol = "\\S:\sourcepath" 
    DestFol = "\\S:\destination\"& variable1 &" - "& variable2 
    result = "Succeeded in string set: 1" 
Else 
    result = "Client Code did not match comparison results [" & ClientCode & "]" 
End If 

If Err.Number<>0 Then 
    WScript.Echo "Error: " & Err.Number 
    WScript.Echo "Source: " & Err.Source & "Description:" & Err.Description 
    Err.Clear 
Else 
    wscript.echo result 
End If 
+0

謝謝你在Err部分的視覺效果,但是我仍然沒有得到輸出,而且我覺得我已經在某處做了一些新手/愚蠢的錯誤...我已經聲明瞭一切,cmd_click()將使用的按鈕的選項,仍然沒有得到任何迴應。 –

+0

你是直接在outlook宏字段中編程嗎? – Rich

+0

這些正在用於自定義任務表單中,由可點擊的按鈕定向。它們也可以從宏按鈕運行。我現在用一種不同的方法來解決這個問題。我現在的麻煩在於將文件移動並重命名。 –

相關問題