|
-
Apr 22nd, 2004, 05:18 AM
#1
Thread Starter
Evil Genius
Returning UDT from Class Function
Hi everyone!!!
According to this page (http://msdn.microsoft.com/vba/Prodinfo/features.asp) this should be possible to do! I've got the following code I'm trying to use in a word vba class module (which has been made public):
VB Code:
Public Type udtSTYLEFONTINFO
Bold As Boolean
CharacterSpacing As Integer
Colour As String
Italic As Boolean
Size As Integer
SmallCaps As Boolean
Underline As Boolean
End Type
Public Function GetStyleFontInfo(ByVal strStyleName As String) As udtSTYLEFONTINFO
GetStyleFontInfo.bold = true
End Sub
When I hit space after the as part of the function declaration, or try to write the .bold = true part, I get no intellisense for the custom udt appear. If I try to run the code, it highlights the "As udtSTYLEFONTINFO" part stating "User defined type not defined".
Um, HELP!!!!! please!
-
Apr 22nd, 2004, 07:21 AM
#2
Addicted Member
From my shallow skill level, it looks good to me....
Just as a guess, did you copy and paste that code in? Sometimes VBA will trip out for some reason and re-doing the line breaks will fix things (or retyping things by hand).
edit: I don't have a clue what you are doing with that code, but I pasted it into an Excel 2003 VBA module. I put the Public Type decleration in the global objects area and passed the function a string. Nothing happened, but I didn't get any errors.
Last edited by Garratt; Apr 22nd, 2004 at 07:27 AM.
-
Apr 22nd, 2004, 08:27 AM
#3
Thread Starter
Evil Genius
Thanks for the reply there Garratt I'm trying to use a UDT (a variable which can hold several different data types like integers, strings etc) to hold several pieces of information about a word style (such as whether the style's font is bold (which is a true/false value), the style's indent (which is a numerical value) etc.
I pasted it then added the line break so it'll look okay on this page. I've managed to sort it a different way now but I'd like to know if anyone can actually get this working/whether this is possible to do as above.
-
Apr 24th, 2004, 05:07 PM
#4
It looks like it works fine for me. I pasted the public type into a
module and I put the function into a class. The in the
ThisWorkbook class I declared a var of my class type and
instanciated the class. Then I call the function in the class an it
run ok. I get the intellisense and udt as well.
VB Code:
'Standard Module (module1)
Public Type udtSTYLEFONTINFO
Bold As Boolean
CharacterSpacing As Integer
Colour As String
Italic As Boolean
Size As Integer
SmallCaps As Boolean
Underline As Boolean
End Type
'Public Class (Class1)
Public Function GetStyleFontInfo(ByVal strStyleName As String) As udtSTYLEFONTINFO
GetStyleFontInfo.Bold = True
End Function
'ThisWorkbook class
Option Explicit
Private classTest As Class1
Private Sub Workbook_Open()
Set classTest = New Class1
classTest.GetStyleFontInfo ("Arial")
End Sub
Is this what you were trying to do?
BTW, Excel 2003
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|