Method OnAction failed

C

CLarkou

I developed an add-in in Office XP. I am assigning procedure names on
my toolbar buttons and I am creating temporarily on menu bar a new
item for my program. As soon as client tries to select any button from
my toolbar or any item from the menu bar, error appears "Method
OnAction of object '_CommandBarButton' failed". Is there any solution
for this ?

This is the code I am using:

Dim cbr_menu As CommandBar
Dim cbr_control As CommandBarControl
Dim cbr_button As CommandBarButton

'-------------------------------------- Excel MENU
-----------------------------

Set cbr_menu = CommandBars.ActiveMenuBar 'Worksheet Menu Bar

Set cbr_control = cbr_menu.Controls.Add(msoControlPopup, , , , True)

With cbr_control
.Caption = "MyProgram"
.Tag = "MyProgram"
End With

'--------------------------------------------------------------

'open database
Set cbr_button = cbr_control.Controls.Add(msoControlButton, , , ,
True)

With cbr_button
.Style = msoButtonCaption
.Caption = "Select Database"
.Tag = "Select Database"
.OnAction = "MNU_show_Ufr_databases_list"
End With
 
B

bmuller

I have a .log file generated by another piece of software. This .log file
consists of 400 numerical data points separated by tabs. I want to import
these points into Excel for further manipulation. Problem is, Excel wants to
import this data as 400 columns, and can't, being limited to 256 columns. My
workaround is to import the data into Word, do a find/replace of the tabs to
paragraphs, and then import it as 400 rows. Is there a way that does not
rely on Word?

Thanks

bern
 
D

Dave Peterson

One way:

Option Explicit
Sub testme01()

Dim myFileName As Variant
Dim myFileNum As Long
Dim myLine As String
Dim wks As Worksheet
Dim oCol As Long
Dim mySplit As Variant

Set wks = Worksheets.Add

myFileName = Application.GetOpenFilename(filefilter:="LOG Files, *.log")

If myFileName = False Then
Exit Sub 'user hit cancel
End If

myFileNum = FreeFile()
Close #myFileNum
Open myFileName For Input As #myFileNum

oCol = 0
Do While Not EOF(myFileNum)
Line Input #myFileNum, myLine
mySplit = Split97(myLine, vbTab)
wks.Range("a1").Offset(0, oCol) _
.Resize(UBound(mySplit) - LBound(mySplit) + 1).Value _
= Application.Transpose(mySplit)
oCol = oCol + 1
Loop
Close #myFileNum

End Sub


Public Function ReadUntil(ByRef sIn As String, _
sDelim As String, Optional bCompare As Long _
= vbBinaryCompare) As String
Dim nPos As String
nPos = InStr(1, sIn, sDelim, bCompare)
If nPos > 0 Then
ReadUntil = Left(sIn, nPos - 1)
sIn = Mid(sIn, nPos + Len(sDelim))
End If
End Function

Public Function Split97(ByVal sIn As String, Optional sDelim As _
String, Optional nLimit As Long = -1, Optional bCompare As _
Long = vbBinaryCompare) As Variant
Dim sRead As String, sOut() As String, nC As Integer
If sDelim = "" Then
Split97 = sIn
End If
sRead = ReadUntil(sIn, sDelim, bCompare)
Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(sIn, sDelim)
Loop While sRead <> ""
ReDim Preserve sOut(nC)
sOut(nC) = sIn
Split97 = sOut
End Function

The last two subs are stolen from an MSKB.
http://support.microsoft.com/default.aspx?scid=kb;en-us;188007
HOWTO: Simulate Visual Basic 6.0 String Functions in VB5

If you're using xl2k or higher, you can dump these two routines and change
split97 to split. (Split was added in xl2k.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top