Variable not defined

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
780
Office Version
  1. 365
Hi,

i got this vba code in the internet and added to outlook and create a rule per instructions but every time i run it
gave an error variable not define, could you please check for me which variables are not define in this code, much appreciated.

here the code:

Code:
Sub LSPrint(Item As Outlook.MailItem)On Error GoTo OError


'detect Temp
Dim oFS As FileSystemObject
Dim sTempFolder As String
Dim cTmpFld As String
Set oFS = New FileSystemObject


'Temporary Folder Path
sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)


'creates a special temp folder
cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
MkDir (cTmpFld)


'save & print
Dim oAtt As Attachment
Dim FileName As String
For Each oAtt In Item.Attachments
FileName = oAtt.FileName
[B][COLOR=#ff0000]FullFile = cTmpFld & "\" & FileName[/COLOR][/B]

'save attachment
oAtt.SaveAsFile (FullFile)


'prints attachment
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(0)
Set objFolderItem = objFolder.ParseName(FullFile)
objFolderItem.InvokeVerbEx ("print")


Next oAtt


'Cleanup
If Not oFS Is Nothing Then Set oFS = Nothing
If Not objFolder Is Nothing Then Set objFolder = Nothing
If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing
If Not objShell Is Nothing Then Set objShell = Nothing


OError:
If Err <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Err.Clear
End If
Exit Sub


End Sub

thank you,
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Fullfile hasn't been defined

Should be dim FullFile as string

Code:
FullFile = cTmpFld & "\" & FileName
 
Upvote 0
thank you very much for the help.

now when run game same error and another line

Code:
[COLOR=#B22222]Set objShell = CreateObject("Shell.Application")[/COLOR]
Set objFolder = objShell.NameSpace(0)
Set objFolderItem = objFolder.ParseName(FullFile)
objFolderItem.InvokeVerbEx ("print")

Thanks again
 
Upvote 0
Add
Code:
Dim objShell as Object
Dim objFolder as Object
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top