Link to home
Start Free TrialLog in
Avatar of fjkilken
fjkilken

asked on

Need to open text file for use in Excel Backstage/Ribbon component

Hi
I am looking to assign dynamic text to the label property a labelControl object in a custom Backstage/Ribbon project(in Excel), this text needs to come from an external text file.

I am looking for a method similar to the one which currently works when I want to reference an image file per below:

Sub getImage(control As IRibbonControl, index As Integer, ByRef image)
Set image = LoadPicture("c:\temp\image1.jpg")
End Sub

The labelControl object has a callback property (getLabel), which I intend to use in order to feed the text from the external text file to it.

So something like:

Sub getExternalText(control As IRibbonControl, ByRef textfile)
Set textfile= LoadFile("c:\temp\test.text")
End Sub

..would be great if it worked.

Appreciate any suggestions

Thanks a lot
Fergal
Avatar of Rgonzo1971
Rgonzo1971

ASKER CERTIFIED SOLUTION
Avatar of fjkilken
fjkilken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fjkilken

ASKER

Sub importTextFile(control As IRibbonControl, ByRef labeltext)
Dim fname As String
Dim sVal As String
fname = "C:\temp\Test.txt"
labeltext = OpenTextFileToString(fname)
'Debug.Print sVal
'MsgBox sVal
End Sub

Function OpenTextFileToString(ByVal strFile As String) As String
Dim hFile As Long
hFile = FreeFile
Open strFile For Input As #hFile
OpenTextFileToString = Input$(LOF(hFile), hFile)
Close #hFile
End Function