Advertisement
adamchilcott

importVCardsBulk.vbs

Aug 24th, 2018
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub OpenSaveVCard()
  2.    
  3. Dim objWSHShell As IWshRuntimeLibrary.IWshShell
  4. Dim objOL As Outlook.Application
  5. Dim colInsp As Outlook.Inspectors
  6. Dim strVCName As String
  7. Dim fso As Scripting.FileSystemObject
  8. Dim fsDir As Scripting.Folder
  9. Dim fsFile As Scripting.File
  10. Dim vCounter As Integer
  11.    
  12. Set fso = New Scripting.FileSystemObject
  13. Set fsDir = fso.GetFolder("C:\vcards")
  14.  
  15. For Each fsFile In fsDir.Files
  16.  
  17. 'original code
  18. 'strVCName = "C:\vcards\" & fsFile.Name
  19.  
  20. 'Zeda's fix for spaces in filenames
  21. strVCName = """C:\vcards\" & fsFile.Name & """"
  22.  
  23.     Set objOL = CreateObject("Outlook.Application")
  24.     Set colInsp = objOL.Inspectors
  25.         If colInsp.Count = 0 Then
  26.         Set objWSHShell = CreateObject("WScript.Shell")
  27.         objWSHShell.Run strVCName
  28.         Set colInsp = objOL.Inspectors
  29.     If Err = 0 Then
  30.             Do Until colInsp.Count = 1
  31.                 DoEvents
  32.             Loop
  33.             colInsp.Item(1).CurrentItem.Save
  34.             colInsp.Item(1).Close olDiscard
  35.             Set colInsp = Nothing
  36.             Set objOL = Nothing
  37.             Set objWSHShell = Nothing
  38.         End If
  39.     End If
  40.  
  41. Next
  42.  
  43. End Sub
  44.  
  45. ' START NOTES
  46.  
  47. ' Reference:
  48. ' <https://www.slipstick.com/developer/macro-to-bulk-import-vcards>
  49.  
  50. ' END NOTES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement