Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Syntax Error in Macro Code....

Hello Experts,

Can anybody suggest what is the syntax error in following code:

Code:

sub ExcelPath

dim Path

Path="C:\"

MsgBox "Path Assigned"

call ExportChart

end sub

Sub ExportChart

set XLAppWholeChart = CreateObject("Excel.Application")

XLAppWholeChart.Visible = False

set XLDocWholeChart = XLAppWholeChart.Workbooks.Add

ActiveDocument.GetSheetObject("CH528").CopyTableToClipboard true

XLDocWholeChart.Sheets(1).Paste()

XLDocWholeChart.Sheets(1).Name = "Export"

TableName="Flash Summary.xlsx"

File=Path&TableName

delfile(file)

XLDocWholeChart.SaveAs File

XLAppWholeChart.Quit

MsgBox "Exported"

'Object creation

call smtpsettings

end sub

sub delfile(file)

Set filesys = CreateObject("Scripting.FileSystemObject")

If filesys.FileExists(file) Then

filesys.DeleteFile file

End If

MsgBox "File Deleted"

end sub

sub smtpsettings

Dim objEmail

Const cdoSendUsingPort = 2   'Send the message using SMTP

Const cdoAnonymous = 0        'Do not authenticate

Const cdoBasic = 1                  'basic (clear-text) authentication

Const cdoNTLM = 2                                 'NTLM

Const SMTPServer = "smtp"

Const SMTPPort = 5                               ' Port number for SMTP

Const SMTPTimeout = 60                        ' Timeout for SMTP in seconds

'Sending mail

Set objEmail = CreateObject("CDO.Message")

Set objConf = objEmail.Configuration

Set objFlds = objConf.Fields

With objFlds

'———————————————————————

' SMTP server details

.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort

.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer

.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort

.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = SMTPTimeout

.Update

'———————————————————————

End With

objEmail.To = ""

objEmail.From = ""

objEmail.Subject = "Flash Summary"

objEmail.AddAttachment "C:\"

objEmail.Send

Set objFlds = Nothing

Set objConf = Nothing

Set objEmail = Nothing

               MsgBox ("Test Mail Sent")

End Sub

Regards,

Balraj

29 Replies
flipside
Partner - Specialist II
Partner - Specialist II

Have you tested the code in the Module editor? Click 'check' (top left), highlight the macro subroutine name in the box below the 'check' button, then click 'Test'. A MsgBox should work with any Module and Local Security levels.

If this doesn't work, have you ever had any macros working?

flipside

Anonymous
Not applicable
Author

I have checked in Module editor, its showing me ****Ready****.........

No, first time working with Macro....

Done all the things, which shared by community peoples but not getting any success..

flipside
Partner - Specialist II
Partner - Specialist II

Can you see any subroutines listed in the box to the left of the editor? If not try clicking the 'Check' button above it. THEN, click a subroutine in the list box and click 'Test'.

We need to know if the error is with your VBScript setup or the way you are calling the macro.

Anonymous
Not applicable
Author

Yes,

all the subroutines are coming in the box of the editor....

flipside
Partner - Specialist II
Partner - Specialist II

And when you test a simple one with a MsgBox, the message box appears? (Remember it may appear but be hidden behind other open programs on screen).

Anonymous
Not applicable
Author

Today only, I checked it as suggested by community people but I did not get any message box.

Just now I again checked but no luck

flipside
Partner - Specialist II
Partner - Specialist II

Okay, try if vbscript is working OUTSIDE of Qlikview.

Go to your desktop and create a new text file but name it test.vbs (make sure there is no .txt extension). Edit the file in Notepad and put one line ...

MsgBox "Hello"

.. then save it.

Double click the file to run it and tell me if a "Hello" messagebox appears.

sivarajs
Specialist II
Specialist II

Looks problem with button.. put the screenshot of your button action here

flipside
Partner - Specialist II
Partner - Specialist II

If the code doesn't work when tested in the Edit Module screen as has been confirmed, then it's unlikely the button configuration will make any difference.

I think we need to ensure that VBScript CAN be run on the machine.

Anonymous
Not applicable
Author

The problem is on parameters.

I think run macro don't accept parameters.....