none
Error "Compile error: Invalid character" after copy paste operations in VBE 6.5 PowerPoint 2011 RRS feed

  • Question

  • This is a weird problem with the VBE 6.5 in Office 2011, running natively on a Mac.

    Sometimes, yet often, when I select a word by double clicking on it or a line by highlighting that line in the editor and then copy/paste it somewhere else in the code, the compiler throws the error "Compile error: Invalid character"

    The thing is, what I see has been pasted is exactly the same as the source text. However, if I then paste the same clipboard item to a text editor, I can see that there is an 'invisible' character at the end of the string which is counted in the text editor where the cursor is shifted past it but does not shown on the screen!!!

    Back in the VBE, if I select a line that is dubious and drag it, the semi transparent dragged text has a '>' character on a new line.

    In some copy/paste cases, the compiler doesn't see an error but the code doesn't work as expected and I have spent hours debugging stuff that has invisible characters in it (the hardest debugging I've ever had to do!).

    I'm not sure if this example will paste correctly into the forum but this looks like 19 characters but is in fact 20 as there is the offending copy/paste invisible character between 'Test' and '.'

    <code>Test.Value = False</code>

    This seems to be a major oversight in the code of the VBE 6.5 so are Microsoft aware of this and when is it due to be fixed?


    Jamie.

    Thursday, July 12, 2012 9:46 AM

All replies

  • I had this exact issue.  This is a terrible bug.  The code looks perfect, but there are hidden characters that throw compiler errors.  Thanks for the quick fix, Microsoft.
    Wednesday, January 7, 2015 12:30 AM
  • I currently have this exact issue and it's killing my productivity... O_o
    Friday, January 23, 2015 7:41 PM
  • Same issue here.  The workaround is to do a backspace after pasting, which removes the invisible character.  Annoying!!!
    Friday, May 22, 2015 9:30 PM
  • I just had this exact same problem with Excel for Mac 2011 version 14.5.5 and the trick with backspace after pasting helped!
    Monday, September 21, 2015 5:29 PM
  • It's even more frustrating when the invisible character isn't at the end of a line and you have no idea where it is. This happens to me quite often while copying variable names from other parts of the VB editor. 

    I found a workaround while keeping your hands mostly on the keyboard: Open TextEdit (cmd+Shift , type TextEdit, then return), and create a new Plain Text document (cmd+ N, Then cmd, shift + T). Paste the text into that document. This will reveal any invisible return characters. Edit as necessary, copy it again, and paste it back in the VB editor. That should take care of it. 

    I keep a plaint text document open at most times for situations like this. Sometimes you just need text.

    Friday, September 23, 2016 2:24 PM
  • I just found a situation where the hidden return character was inside a quote, so it didn't complain at compile time. Instead, I banged my head on a desk 50 times trying to figure out what was wrong with my code. 

    Pasting it into a plaintext document revealed it. 

    ElseIf userSelectedForms(x) = "contemptRemedies" Then

    in plaintext = 

    ------

    ElseIf userSelectedForms(x) = "contemptRemedies

    " Then

    -------

    Fun stuff. I hope this helps someone else. 


    • Edited by brett_pww Monday, September 26, 2016 6:30 PM Edited for clarity
    Monday, September 26, 2016 6:28 PM
  • Due to my workflow, I am encountering this on a very regular basis. 

    In case anyone really struggles with this like I have, once you find one instance of it, you can copy it, and do a find and replace all to eliminate the problem anywhere else in the project.

    HTH. 

    Tuesday, October 18, 2016 7:15 PM