PC Review


Reply
 
 
E.Z.
Guest
Posts: n/a
 
      30th May 2009
Hi,
Can some1 tell me what's wrong with this line:

UserForm1.Controls.Add "Excel.Sheet", "List1", True

I get Run time error - Invalid argument

Tnx in advance


 
Reply With Quote
 
 
 
 
E.Z.
Guest
Posts: n/a
 
      30th May 2009
Tnx,
It's a UserForm and the problem is with adding an "Excel.Sheet" control
class.
np with adding a ListBox


"royUK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Here's some sample code to add a userform with a listbox & some code
>
> Code:
> --------------------
>
>
> Option Explicit
> Dim uFrm
> Sub uFrm_Create()
>
> Dim Lbox As MSForms.Control
>
>
> uFrm_Remove ' If Userform1 exists then remove it.
>
> With ThisWorkbook.VBProject.VBComponents
> Set uFrm = .Add(3).Designer ' Create & set form designer
> End With
>
> With uFrm.Controls
> Set Lbox = .Add("Forms.listbox.1")
>
> With Lbox
> .ColumnCount = 1
> .Top = 12
> .Left = 6
> .Width = 100
> .Height = 40
> End With
> End With
> ufrm_Code
> ufrm_Show
> uFrm_Remove
> End Sub
> Sub ufrm_Show()
>
> With UserForm1.ListBox1
> Dim ws As Worksheet
> On Error Resume Next
> For Each ws In ActiveWorkbook.Sheets
>
> If ws.Visible And Application.CountA(ws.Cells) > 0 Then
> With UserForm1.ListBox1
> .AddItem ws.Name
> End With
> End If
> Next ws
> End With
> With UserForm1
> .Caption = "Sheet List"
> .Height = 95
> .Width = 125
> .Show
> End With
>
> On Error GoTo 0
> End Sub
> Function ufrm_Code()
> With ThisWorkbook.VBProject.VBComponents("Userform1").CodeModule
> .InsertLines 2, "Private Sub ListBox1_Click()"
> .InsertLines 3, "Sheets(Me.ListBox1.Value).Activate"
> .InsertLines 4, "End Sub"
> End With
> End Function
> Function uFrm_Remove()
> On Error Resume Next
> With ThisWorkbook.VBProject
> .VBComponents.Remove .VBComponents("Userform1")
> End With
> Err.Clear
> End Function
>
>
> --------------------
>
>
> --
> royUK
>
> Hope that helps, RoyUK
> For tips & examples visit my 'web site' (http://www.excel-it.com/)
> ------------------------------------------------------------------------
> royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
> View this thread:
> http://www.thecodecage.com/forumz/sh...d.php?t=101878
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem after problem after problem - winXP wont start! =?Utf-8?B?TWF2aXJpY2s=?= Windows XP Help 2 23rd Apr 2006 02:55 PM
Microsoft Access Object Library Version Problem (Form VBA Code Problem) Don Microsoft Access Form Coding 2 8th Mar 2004 01:00 PM
hibernation problem! problem!, Power Option problem! Farzad Hayati Microsoft Windows 2000 Hardware 2 5th Feb 2004 10:22 PM
hibernation problem! problem!, Power Option problem! Farzad Hayati Microsoft Windows 2000 Advanced Server 2 5th Feb 2004 10:22 PM
Outlook 2002 connector: problem connecting with Domino server because of NAMELookup2 problem Jean-Paul Smeets Microsoft Outlook 2 26th Sep 2003 10:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:03 AM.