VBA API Changes for Excel 64 bit?

Post Reply
TJMurphy
Posts: 74
Joined: Mon May 12, 2008 12:25 pm
OLAP Product: TM1
Version: PA 2.0.6 Local
Excel Version: Excel 2016

VBA API Changes for Excel 64 bit?

Post by TJMurphy »

Hi all,
Our company has decided to roll out 64bit Excel on us with minimal advance notice (yay us!).

So, I've got a brand new test PC and installed Office 64bit on it. I also installed the TM1 Perspectives 64 bit addin. So far so good, I can connect to the server, run reports and so on. Testing is ongoing but I've just spent a day on something and not gotten anywhere so hoping someone else can point me in the right direction.

We have some Excel models that use the TM1 API in VBA to fire off some TI processes. I can't make these run now under 64bit. I've put "PtrSafe" in all the declarations and they compile fine. It still runs in the 32bit version after this.

When I step through the code it's working fine until it calls TM1SystemServerHandle (hUser, sServer). On this line, Excel just crashes, every time.

There *are* values for hUser and sServer. I believe this means the API is connected / working because API calls were used earlier to get a user handle.

Anyone else come across this? Any suggestions?
User avatar
gtonkin
MVP
Posts: 1198
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: VBA API Changes for Excel 64 bit?

Post by gtonkin »

Not at my PC right now but seem to remember having to not only add the PtrSafes but needed to change the ‘As Long’ to ‘As LongPtr’

HTH
jrizk
Posts: 48
Joined: Thu Nov 19, 2009 10:38 pm
OLAP Product: Tm1
Version: 10.2.2
Excel Version: 2010

Re: VBA API Changes for Excel 64 bit?

Post by jrizk »

If you download TM1Tools which was modified for 64bit you should be able to follow the changes required for your models.

https://www.tm1forum.com/viewtopic.php?f=3&t=11593

You have to add PtrSafe/LongPtr to the API declarations as well as LongPtr to the functions and dims that reference the declarations . Even though you are getting values for hUser and sServer they could be error types - which might be because hUser is not being obtained correctly in 64bit and this could be because of the SSL certificates (refer to this post https://www.tm1forum.com/viewtopic.php?f=3&t=14473).

As an example a function to obtain the server handle and runs on 32bit and 64bit would be:

#If Win64 And VBA7 Then
Public Function serverHandle(ByVal s As String) As LongPtr
#Else
Public Function serverHandle(ByVal s As String) As Long
#End If

#If Win64 And VBA7 Then
Dim hPool As LongPtr
Dim hServerName As LongPtr
#Else
Dim hPool As Long
Dim hServerName As Long
#End If

Dim sServerName As String * 75

'Note assumes hUser has been obtained correctly for 32/64bit

If hUser = 0 Then Exit Function

hPool = TM1ValPoolCreate(hUser)

serverHandle = TM1SystemServerHandle(hUser, s)

'= This section is just a check the server handle is valid
hServerName = TM1ObjectPropertyGet(hPool, serverHandle, TM1ObjectName())

If TM1ValType(hUser, hServerName) = TM1ValTypeString() Then
TM1ValStringGet_VB hUser, hServerName, sServerName, 75
Debug.Print sServerName
End If
' =

TM1ValPoolDestroy (hPool)

End Function

Sub getServerHandle()
Call serverHandle("servername")
End Sub
J.Rizk
Tm1 for everyone
TJMurphy
Posts: 74
Joined: Mon May 12, 2008 12:25 pm
OLAP Product: TM1
Version: PA 2.0.6 Local
Excel Version: Excel 2016

Re: VBA API Changes for Excel 64 bit?

Post by TJMurphy »

Awesome, thank you. I can't easily get onto this forum from work so get back here less often than I like.

I'm having some other wierd behaviour too - edit a Declare line, even to just add a space and I'm getting Out of Memory. I'm off to try and run a repair on Excel as well as follow through on the updated add-in.

Updated : Not going to pretend I fully understand what I've done but having commented out all declarations and then copying the ones I needed back in from the TM1 Tools APIs codes and then debugging my code I've got it functioning. The TM1 Tools API code is far clearer than the old IBM one I was using so thanks very much for that.
Post Reply