+ Reply to Thread
Results 1 to 4 of 4

Compile error expected function or variable (on protect method)

  1. #1
    Registered User
    Join Date
    07-02-2008
    Location
    Fort Worth, TX
    Posts
    99

    Compile error expected function or variable (on protect method)

    My company changed servers last week, so I've had to remap all my previous macros from my personal macro workbook. Other than that I haven't really made any changes. To make this more complex, this macro worked fine last week multiple times, yet now it doesn't seem to like me any longer.

    Please Login or Register  to view this content.
    It is failing on the wksht.protect line with the compile error expected function or variable.

    It wont even start the code to assign the activesheet to the worksheet variable. I can immediate debug.print activesheet.protect = true and get a boolean response. I've manually assigned the worksheet variable and it works, but for whatever reason it just wont fire the code unless within the code I use activesheet. I'm flabbergasted as to what the deal is, or what change was made that suddenly cuased it to not work any longer. Thoughts/ideas would be appreciated.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Compile error expected function or variable (on protect method)

    Hi Tirren,

    maybe use ProtectContents to do the check:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    07-02-2008
    Location
    Fort Worth, TX
    Posts
    99

    Re: Compile error expected function or variable (on protect method)

    Thank you HaHoBe, protectcontents does work either with activesheet as well as my defined worksheet variable. ActiveSheet also works with the .protect version as well, but I cannot understand why I cannot simply get the defined variable WS to work independently. Again this worked fine last week, and I cannot imagine any reason it wouldn't work now. I tried renaming the worksheet variable to random names I'm sure I've never used before just to ensure I didn't have a duplicate variable declared somehow, but still no go on that. If I type out the worksheets("sheetname").protect, and test it, it also works.

    Sadly,

    Please Login or Register  to view this content.
    also works. What is wrong with Excel?!
    Last edited by Tirren; 09-30-2013 at 03:17 PM.

  4. #4
    Registered User
    Join Date
    07-02-2008
    Location
    Fort Worth, TX
    Posts
    99

    Re: Compile error expected function or variable (on protect method)

    I'm going to just go with HaHoBe's response as a solution since it does work and excel is just being odd today.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compile error: Expected variable or procedure, not module
    By kaseyleigh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2015, 03:46 PM
  2. [SOLVED] With my user defined function... Compile Error: Expected: =
    By kid_epicurus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2012, 04:03 PM
  3. Mac issue (please help) "Compile error: Expected Function or variable"
    By m1notaur in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-22-2011, 06:00 PM
  4. Compile Error:- expected function or variable problem
    By skin.uk1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-08-2011, 02:56 PM
  5. [SOLVED] Compile error: Expected Sub, Function, or Property
    By Cloudfall in forum Excel General
    Replies: 3
    Last Post: 08-30-2005, 01:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1