Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30387
    Waheed Alsayer
    Participant

    Hi,
    Why does this macro gives an error at line 2

    document.selection.StartOfDocument
    editor.ExecuteCommandByID 4472 ' no csv 
    editor.ExecuteCommandByID 3889 ' Vertical Selection
    document.selection.Text = document.FileName
    document.selection.Collapse()
    #30388
    Waheed Alsayer
    Participant

    Eventhough I would like to know why I got this error, I found another method of doing the same.
    I used Find and Replace in files,
    Find: ^
    Replace: $(Filename)|

    And it worked.

    #30389
    Patrick C
    Participant
    #30391
    Stefan
    Participant

    That brings still the error      on Line 2:      “;” awaited

    But adding an explicit >>#language =”VBScript”<< on the first line, let the script work.

     

    #language ="VBScript"
    document.selection.StartOfDocument
    editor.ExecuteCommandByID 4472 ' no csv 
    editor.ExecuteCommandByID 3889 ' Vertical Selection
    document.selection.Text = document.FullName + "  "
    document.selection.Collapse()

     
    HTH?

    #30393
    Waheed Alsayer
    Participant

    Thanks,
    Ok, I’ll add the #language
    but I don’t want the full path, just the file name without the extension.

    #30394
    Patrick C
    Participant

    just the file name without the extension

    To my knowledge EmEditor has not got a document name without extension property.

    In JavaScript I’d do the following:

    let bareName = "";
    let iLastIdx = document.Name.lastIndexOf(".");
    if (iLastIdx > 0) {
      bareName = document.Name.substring(0, iLastIdx);
    }
    OutputBar.writeln("bareName = «" + bareName + "»");
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.