Announcement

Collapse
No announcement yet.

Compile error:Syntax error on MSExcel exercise

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compile error:Syntax error on MSExcel exercise



    Hi
    Question from a beginner to VBA.

    Below is a code which i have copied from the ExcelVBA help. The exercise is about MultiPages. I have copied the code below as it appears in ExcelVBA Help. When i try to run, it gives me a Syntax error on the folowing line:
    .Add("MSForms.TextBox.1", "MyTextBox", Visible)

    Below is the code in full:

    Code:
    Private Sub CommandButton1_Click()
        Set MyTextBox = MultiPage1.Pages(MultiPage1.Value).Controls_
        .Add("MSForms.TextBox.1", "MyTextBox", Visible)
        CommandButton2.Enabled = True
        CommandButton1.Enabled = False
    End Sub
    
    Private Sub CommandButton2_Click()
        MultiPage1.Pages(MultiPage1.Value).Controls.Cut
        CommandButton3.Enabled = True
        CommandButton2.Enabled = False
        
    End Sub
    Private Sub CommandButton3_Click()
        Dim MyPage As Object
        Set MyPage = _
            MultiPage1.Pages.Item(MultiPage1.Value)
            
            MyPage.Paste
            CommandButton3.Enabled = False
            
    End Sub
    
    Private Sub MultiPage1_Change()
    
    End Sub
    
    Private Sub UserForm_Initialize()
        CommandButton1.Caption = "Add"
        CommandButton2.Caption = "Cut"
        CommandButton3.Caption = "Paste"
        
        CommandButton1.Enabled = True
        CommandButton2.Enabled = False
        CommandButton3.Enabled = False
    End Sub
    Much Appreciated
    Suju
    Your help is appreciated
    Suju

  • #2
    Suju,

    I have come across this before.

    In the line that is creating the problem you need to insert a space before the underscore ( _ ) that causes the line to wrap.

    It should be fine after that.

    Regards
    Weasel
    Kind Regards
    Pesky Weasel
    "I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
    Eagles may soar, but Weasels don't get sucked into jet engines.
    Templates and Calculators
    The Way of the Weasel
    Download Ivan & Colo's HTML Maker Here
    101 Excel Hacks - Great New Book
    Huge Savings on Excel Training

    Comment


    • #3
      ... and who said Help meant Help

      suju-


      I've got the same example in my help as yours. So I made the form as directed, and I got errors as well.

      I also thought that the ("_") was the issue, but it wasn't. The error that I got was invalid class string.

      If you look closely at the help it says that the progid for a text box is Forms.TextBox.1

      However, in the Help example it's coded as MSForms.TextBox.1


      If you remove the "MS" the code works.!!
      Regards,
      Barry

      My Favorite New Thing:
      Dynamic Named Ranges



      The alternative for
      "Press Any Key To Continue."

      and we all have one we'd like to use it on

      1. Cross Posting Etiquette
      2. Are You Here To Learn: What Have You Tried?
      3. Your Best Resource to begin learning VBA: RECORD A MACRO . . . Then Study It!

      Comment


      • #4
        Good pick up iwrk4dedpr!

        I hadnt run the code to test it just saw the "_" problem. I thought a typo error like a missing space was one thing but a wrong ProgID??????

        Weasel
        Kind Regards
        Pesky Weasel
        "I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
        Eagles may soar, but Weasels don't get sucked into jet engines.
        Templates and Calculators
        The Way of the Weasel
        Download Ivan & Colo's HTML Maker Here
        101 Excel Hacks - Great New Book
        Huge Savings on Excel Training

        Comment


        • #5
          Syntax error

          Originally posted by Pesky Weasel
          Suju,

          I have come across this before.

          In the line that is creating the problem you need to insert a space before the underscore ( _ ) that causes the line to wrap.

          It should be fine after that.

          Regards
          Weasel
          Hi Weasel
          Thanx . Tried that also, doesnt work. i too have come across the underscore error.

          Suju
          Your help is appreciated
          Suju

          Comment


          • #6
            Suju,

            Did you try iwrk4dedpr's solution? He nailed it and it works fine with his fix.

            Weasel
            Kind Regards
            Pesky Weasel
            "I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
            Eagles may soar, but Weasels don't get sucked into jet engines.
            Templates and Calculators
            The Way of the Weasel
            Download Ivan & Colo's HTML Maker Here
            101 Excel Hacks - Great New Book
            Huge Savings on Excel Training

            Comment


            • #7
              Re: Compile error:Syntax error on MSExcel exercise

              Compile Error:
              Syntax Error


              the above error is coming for the below code . it happens when inject the Day condition

              Private Sub TestFileExistence()


              If FileFolderExists("\\cf3.pepsico.pvt\psra\Output\BI4\Exec Dollars - Current Period.pdf")and
              weekday(date) = 2 Then

              Range("A1").Value = "X"


              Else


              Range("A1").Value = "!"




              End If




              End Sub
              Last edited by Usman1158; November 14th, 2014, 00:00.

              Comment


              • #8


                Re: Compile error:Syntax error on MSExcel exercise

                Usman

                You are replying in a topic that is more than 10 years old.
                Use your common sense and start a new topic if you have a question.
                Thanks.
                Regards,

                Wigi

                Excel MVP 2011-2014

                For more Excel memes: visit http://www.wimgielis.com ==> English articles ==> Excel memes

                -- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --

                Comment

                Working...
                X