Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

"Object doesn't support this property or method" when run sending email module

Hi,

I simply copied the module code from another qlikview file, which runs perfect all the time on that file. However, using the same computer, the code can't run on my current file, and there is an error "Object doesn't support this property or method: 'obj.GetRowCount'".

How can the same code can't run on another file? So confused.

Thanks!

Here is the code:

Sub send_alerts()

set objExcel=nothing

set strDate=nothing

set filepath=nothing

Set objMsg = CreateObject("CDO.Message")

Set msgConf = CreateObject("CDO.Configuration")

Set xlFile = CreateObject("Excel.Application")

Set wksht = ActiveDocument.Activesheet

ActiveDocument.Reload

With msgConf

    ' ** OUT GOING SMTP SERVER **

    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xx.xx.xxx.xxx"

    ' ** SMTP PORT **

    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    ' ** CDO PORT **

    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    ' ** TIMEOUT **

    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

    .Fields.Update

End With

str=""

cnt1 = 0

Set objMsg.Configuration = msgConf

WITH xlFile 

      .DefaultSaveFormat = xlWorkbookNormal 

      .DisplayAlerts = FALSE 

      .Workbooks.Open "S:\aa\bb\cc\abc.xlsx"

      .DisplayFullScreen = TRUE 

      .Visible = TRUE 

   END WITH

Set wksht1 = xlFile.Worksheets(1)

wksht1.Range("A1:AA1000").ClearContents

'ActiveDocument.GetApplication.Sleep 10000

col = 0

flag = 0

for i = 0 to wksht.NoOfSheetObjects-1 

set obj = wksht.SheetObjects(i)

cnt = obj.GetRowCount     <--error happens here

if(cnt>1) Then

flag = flag + 1

str1 = mid(obj.GetObjectId,10)

'msgbox(str1)

if(cnt1 = 0) Then

str = str & str1

cnt1 = cnt1 + 1

Else

str = str & ", "& str1

cnt1 = cnt1 + 1

End if

str = str & vbNewLine & myRange

Set ObjectFrom = ActiveDocument.GetSheetObject(obj.GetObjectId)

j = ObjectFrom.GetRowCount

k = ObjectFrom.GetColumnCount

m = 0

wksht1.Cells(col+1,1).Value = str1

wksht1.Cells(col+1,1).Font.Bold = True

For x = (1 + col + 1) to (j + col + 1)

  For y = 1 to k

  wksht1.Cells(x,y).Value = ObjectFrom.GetCell(m,y-1).Text

  Next

  m = m + 1

Next

col = col + j + 2

'ActiveDocument.GetApplication.Sleep 1000

Else

End if

Next

wksht1.SaveAs "S:\aa\bb\cc\abc.xlsx"

'ActiveDocument.GetApplication.Sleep 10000

xlFile.Quit

if(flag > 0) Then

ActiveDocument.GetApplication.Sleep 2000

objMsg.To = "xx@xx.edu"

objMsg.From = "xxx@xxx.edu"

objMsg.Subject = "Collateral report"

objMsg.HTMLBody = str & " table(s) are not null"

objMsg.AddAttachment "S:\aa\bb\cc\abc.xlsx"

objMsg.Send

Else

End if

set objMsg = Nothing

set msgConf = Nothing

End Sub

3 Replies
marcus_sommer

I think you need GetSheetObject instead of SheetObjects like in this example (from APIGuide.qvw):

set table = ActiveDocument.GetSheetObject( "CH01" )

CellRect = ActiveDocument.GetApplication().GetEmptyRect()

CellRect.Top = 0

CellRect.Left = 0

CellRect.Width = table.GetColumnCount

CellRect.Height = table.GetRowCount

set CellMatrix = table.GetCells( CellRect )

for RowIter=CellRect.Top to CellRect.Height-1

    for ColIter=CellRect.Left to CellRect.Width-1

        msgbox(CellMatrix(RowIter)(ColIter).Text)

    next

next

- Marcus

Not applicable
Author

Thanks Marcus! I have a try but it doesn't work, error says "Object doesn't support this property or method: 'GetSheetObject'"

However, with my previous code, even though I got error message, but when I run the code I can get the excel with content that I want to send, but just can't send email successful.

I don't understand, how can an error message existing but I can still get the excel file with content I want?

Thanks!

Bo

Not applicable
Author

Finally I solve this strange issue by replacing reload data code in my previous could-send-email file, and create all table and chart again...