Jump to content
Macro Express Forums

terrypin

Members
  • Posts

    2,230
  • Joined

  • Last visited

  • Days Won

    23

Everything posted by terrypin

  1. First, I assume you've now successfully run the macro? -------------------- Re your latest questions: To copy command text from the Script Editor: Select all > Right click > Copy Command Text To copy code from the Script Editor or Direct Editor: Select all > Ctrl+C Yes, it's just convenient to paste both commands and code into the Code box. Some of us do that and others open separate boxes. For a recipient, it's a matter of seconds to run a macro from its pasted code. Even faster than importing an MEX I'd think. And either method usually then requires editing to be sure the macro runs successfully in the recipient's environment.
  2. The fastest way to re-assign variables after pasting the code into a new macro is to simply hit Ctrl+s to start a Save. MEP will then prompt repeatedly as shown in my screenshot, and you then tap Enter (or Y) until finished. BTW, note that the six variables I've used are all text types and the three whose types might ever be ambiguous are all prefixed with 't'. I've also exported the file as an MEX. Use File > Import > Import Macros... and browse to the file to import it. It will usually be placed in the Unassigned category. Reassign the variables and Edit the file paths appropriately. Here's a 'Before and After'. Delete-HTML-Section.mex
  3. Using the method I outlined, this delivers the modified HTML in about one second, using your example file. // Set the EOL character for later use. Variable Set to ASCII Char 13 to %CR% // Set CR Variable Set to ASCII Char 10 to %LF% // Set LF Variable Set String %CRLF% to "%CR%%LF%" // Set the 'flag' to 'Retain', so that all such lines will be kept. Variable Set String %tAction% to "Retain" // Start Text Process; Get tLine for each line of HTML Text File Begin Process: C:\users\Test.html // Test for start of section If Variable %tLine% Contains "<section class="tsd-index-section ">" Variable Set String %tAction% to "Ignore" Goto:EndProcess Else // Not start of section // Test for end of selection If Variable %tLine% Contains "</section>" // End of section AND If Variable %tAction% Equals "Ignore" // End of section Variable Set String %tAction% to "Retain" Goto:EndProcess Else // Not end of section // Test if tAction = Retain If Variable %tAction% Equals "Retain" Goto:Add Else Goto:EndProcess End If End If End If :Add // Add this line to the output variable Variable Modify String %tOutput%: Append Text (%tLine%) // Also add an EOL. Variable Modify String %tOutput%: Append Text String Variable (%CRLF%) :EndProcess Text File End Process Text Box Display: Final Output // Disabled after testing // Save to new file Result.html in same folder. (Or immediately replace original if preferred.) Variable Modify String: Save %tOutput% to "C:\Users\Result.html" <COMMENT Value="Set the EOL character for later use."/> <VARIABLE SET TO ASCII CHAR Value="13" Destination="%CR%" _COMMENT="Set CR"/> <VARIABLE SET TO ASCII CHAR Value="10" Destination="%LF%" _COMMENT="Set LF"/> <VARIABLE SET STRING Option="\x00" Destination="%CRLF%" Value="%CR%%LF%" NoEmbeddedVars="FALSE"/> <COMMENT Value="Set the 'flag' to 'Retain', so that all such lines will be kept."/> <VARIABLE SET STRING Option="\x00" Destination="%tAction%" Value="Retain" NoEmbeddedVars="FALSE"/> <COMMENT Value="Start Text Process; Get tLine for each line of HTML" _BACK="0080FFFF"/> <TEXT FILE BEGIN PROCESS Filename="C:\\users\\Test.html" Start_Record="1" Process_All="TRUE" Records="1" Variable="%tLine%"/> <COMMENT/> <COMMENT Value="Test for start of section"/> <IF VARIABLE Variable="%tLine%" Condition="\x06" Value="<section class=\"tsd-index-section \">" IgnoreCase="FALSE"/> <VARIABLE SET STRING Option="\x00" Destination="%tAction%" Value="Ignore" NoEmbeddedVars="FALSE"/> <GOTO Name="EndProcess"/> <ELSE _COMMENT="Not start of section"/> <COMMENT Value="Test for end of selection"/> <IF VARIABLE Variable="%tLine%" Condition="\x06" Value="</section>" IgnoreCase="FALSE" _COMMENT="End of section"/> <AND/> <IF VARIABLE Variable="%tAction%" Condition="\x00" Value="Ignore" IgnoreCase="FALSE" _COMMENT="End of section"/> <VARIABLE SET STRING Option="\x00" Destination="%tAction%" Value="Retain" NoEmbeddedVars="FALSE"/> <GOTO Name="EndProcess"/> <ELSE _COMMENT="Not end of section"/> <COMMENT Value="Test if tAction = Retain"/> <IF VARIABLE Variable="%tAction%" Condition="\x00" Value="Retain" IgnoreCase="FALSE"/> <GOTO Name="Add"/> <ELSE/> <GOTO Name="EndProcess"/> <END IF/> <END IF/> <END IF/> <COMMENT/> <LABEL Name="Add"/> <COMMENT Value="Add this line to the output variable"/> <VARIABLE MODIFY STRING Option="\x06" Destination="%tOutput%" Value="%tLine%" NoEmbeddedVars="FALSE"/> <COMMENT Value="Also add an EOL."/> <VARIABLE MODIFY STRING Option="\x07" Destination="%tOutput%" Variable="%CRLF%" NoEmbeddedVars="FALSE"/> <LABEL Name="EndProcess"/> <TEXT FILE END PROCESS/> <TEXT BOX DISPLAY Title="Final Output" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %tOutput%\r\n\\par }\r\n" Left="502" Top="-1" Width="1243" Height="1175" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE" _COMMENT="Disabled after testing"/> <COMMENT Value="Save to new file Result.html in same folder.\r\n(Or immediately replace original if preferred.)"/> <VARIABLE MODIFY STRING Option="\x11" Destination="%tOutput%" Filename="C:\\Users\\Result.html" Strip="FALSE" NoEmbeddedVars="FALSE"/> <COMMENT/> <COMMENT/>
  4. So it is just that one section to be deleted, uniquely identified by its first line containing the string <section class="tsd-panel tsd-index-panel"> yes? If so one way would be to use Text File Begin Process. Test each line for that string. If it does not contain the string use Variable Modify String > Add Text to build an output variable. When it *is* encountered, skip the Add Text and instead set a flag. Test the flag for each subsequent line and if it is still set continue ignoring the Add Text command But also test for the string </section> and when found reset the flag. The remaining content will then be added to your output variable, which you will finally save to a file, replacing the original. Ah, I see acantor beat me to it, so try his complete macro first!
  5. Yes, sorry, I missed the fact that you were not using Pro. So you want to delete everything in that code block you've posted? If so, can you show us the surrounding content or the entire file?
  6. It may be possible to use the Split String command, depending on the content, so can you post a typical example.
  7. To make sure I’ve correctly understood: 1. What is your screen resolution? 2. Is the middle of the target button, which you’re clicking, at roughly 1520, 220, using Tools > Mouse Locator? 3. Using my amended code for the move, with those coordinates, does the button now get activated correctly and consistently? 4. If not, what exactly is the behaviour you get? 5. If your mouse is battery-powered, is it in need of replacement? 6. Are there any other clues from mouse or graphics quirky behaviour in other apps?
  8. Did you see my picture of the elephant in the room? The mouse locator does not agree with the capture tool. Does yours? As I suggested in my earlier reply, that screenshot appears to show that at the moment you took it the mouse cursor was in a different position to where it was when you used the capture tool to take a snapshot. Try it again a few times: move the mouse, release it, press Ctrl+Space ... and the values entered into the command should exactly match those you see in the Mouse Locator. If not then I'm at a loss to explain it as it always has agreed on all my PCs and in all versions of Macro Express/Macro Express Pro.
  9. Because of the excessive delay time (nearly a full second) after moving the mouse, perhaps vibration or unintended movement has shifted the mouse cursor's position? A mere 0.1 s delay would usually be OK. Often zero too, but I usually err on the cautious side. And I would use the plain Delay command. So I would have written that section thus: Mouse Move: 1520, 220 Relative to Screen Delay: 0.1 seconds Mouse Left Click And the code: <MOUSE MOVE Option="\x01" X="1520" Y="220" _PROMPT="0x000A"/> <DELAY Flags="\x01" Time="0.1"/> <MOUSE LEFT CLICK/> BTW, that's the way you would normally post the macro and its code. Use the 'Code' tool above, '<>'. No need to attach separate files usually. Although if it's an accessible macro (that others could run with no other apps or files needed) then an MEX is a welcome extra. As the button is fixed and you are clicking well within it, I can think of no other cause for the inconsistency. And if you've paused or stopped the macro at that point for a visual check it's strange that you didn't spot anything amiss. One other possibility is that your app may be one of the few I recall that need a particularly 'smooth' approach in a mouse move. Or even simply slowing that down with a Mouse Speed command set to say 5 ms.
  10. 1. Have you radically edited your code since recording it, as acantor recommended? The last screenshot you showed still had evidence of the original, such as redundant delays, etc. 2. Show us your full macro and its code. 3. Place Pauses or Macro Stops at key points and carefully check that - your mouse cursor is where you expected - correct items in the drop-down menu are displayed 4. Check that the Meta-Correction button and its drop-down inset are consistently at the same screen position under all circumstances. For example, no downward displacement due to additional content appearing above. 5. Clarify the point of your last screenshot which shows contradictory entries: 1573 v 1258, and 239 v 192. That looks like you may have moved the mouse since last entering the values?
  11. It's not what you want to hear, but over the years I too have found both Window Activate and Wait for Window Title unreliable. Some instances work, others don't. I can often instead use Delay commands (determined by trial/error). Sometimes I've had to resort to other methods, such as pixel colour recognition, slowing down that section with Macro Playback Speed, etc. This has been my experience over several versions of the OS, probably from 95 , 2000 and XP to Win 10. I assume some sort of timing conflict with the OS and/or other apps running simultaneously with the macro.
  12. Hi John, That would be a fun project to instruct Alexa (if you don't have an Echo/Dot near to the computer). But why is she needed? Just send yourself an email with the single command Email Send (under the Internet menu).
  13. Maybe some sort of time zone issue? If you could post a minimal scheduled macro that causes that behaviour we could try to reproduce. FWIW I regularly use scheduled macros for important reminders. I've never changed the frequency from its default of 10 s, but I don't see that notification. P.S: It's Valentine's day tomorrow!
  14. Interesting, thanks Pete, I'll explore that alternative more thoroughly to see if I can get a simple example working. But from initial study it looks a fair bit more complex than my usual method of launching a VBA macro from an MEP macro, namely with Alt+F8 as discussed up-thread. However it opens up a possible new approach to transferring data between Excel and MEP that I'd never been aware of before. I've been using either - the clipboard - or reading an intermediate (and otherwise redundant) text file. So many thanks for the heads up!
  15. That's very kind of you, Cory, thank you, but I'm going to pass. My list of 'things to learn' is not getting any smaller. So I try to resist most new temptations. Right now I'm doing my best to move beyond my 'google/copy/paste/edit' mode of writing Excel VBA macros. Never having learnt any object based programming language, that's struggle enough for now. And I also need to get back to some practical electronics in the shed workshop to continue my Arduino programming. 😉
  16. Pleased to hear it Brian. Still waiting to hear from Naresh - from nearly three years ago!
  17. Thanks Cory, appreciate your follow-up. But I couldn't get that working here. I tried both my BT Internet and Gmail settings (copied from my offline email program, Forte's Agent). Both gave the same error: https://www.dropbox.com/s/9el2xdxhknbcnhc/CoryVBS-Email-2.jpg?raw=1 I decided against following the detailed instructions here about fixing that error, as I don't want to risk it simply out of curiosity. https://support.microsoft.com/en-gb/help/928100/error-message-when-you-try-to-programmatically-send-an-e-mail-message And as I already have at least three email accounts I'll pass on trying SendPulse. It's not worth your spending much time on but here's a redacted version of what i tried: https://www.dropbox.com/s/it9h8dz165nkp9g/CoryVBScriptToSendEMail-Gmail-Redacted.vbs?raw=1
  18. Thanks Cory. As mentioned, I'm only using VBS as a learning exercise. And now my curiosity is piqued. The script I tried only offered me that Outlook option. Ive tried a few other scripts in vain. That one you suggested looked promising but gave the error 'The transport failed to connect to the server.' Knowing very little about VBS and almost nothing about the obscure workings of email delivery, servers and such, I was hoping to get by in copy/paste/edit mode, with little further investment! I'll put it on the back burner for now. But MEP's command works OK. Terry, East Grinstead, UK
  19. ... Write Myself a Letter. Well, an email. In retirement I no longer need an app such as MLO, like Alexis, but I do set alarms to remind me of important ToDos. Right now I'm trying to add a macro to send an email on a special scheduled date, as a backup to my regular one. I thought I'd also learn a bit more about the External Script command at the same time. The macro works fine except for the rather serious snag that the VBS script apparently insists on user input to close a dialog. It won't let me type Enter or click the mouse to close it. Not much use for an alarm I want to set days or weeks ahead! For this discussion I've shown the macro intended for immediate activation, rather than scheduled. To test just change the email address in the script. Or leave it as it is and you should get a Delivery Status Notification (Failure) email instead. The dialog that won't respond to MEP is shown below. Playing with Options and Properties brought no joy. It seems that VBS takes priority. I'm not clear why a dialog is displayed anyway as there's only one option, Outlook. (I don't use it, but my regular email app, Agent, doesn't support IMAP.) Anyone know enough about VBS to bypass that dialog please? // This macro inserts the text contents of the clipboard into the body of a message and emails it immediately (using Outlook) to my BT address. Delay: 0.1 seconds Variable Set String %tBody% from the clipboard contents Delay: 0.1 seconds External Script: VBScript Wait for Window Title: Choose Profile Text Type (Simulate Keystrokes): <ENTER> <COMMENT Value="This macro inserts the text contents of the clipboard into the body of a message and emails it immediately (using Outlook) to my BT address."/> <DELAY Flags="\x01" Time="0.1"/> <VARIABLE SET STRING Option="\x02" Destination="%tBody%" NoEmbeddedVars="FALSE"/> <DELAY Flags="\x01" Time="0.1"/> <EXTERNAL SCRIPT Language="VBScript" Dest="%tConsole%" Script="Dim ToAddress\r\nDim MessageSubject\r\nDim MessageBody\r\nDim MessageAttachment\r\n\r\nDim ol, ns, newMail\r\n\r\nToAddress = \"abc@xyz.com\" ' Change this to your own address to test\r\nMessageSubject = \"Test using VBS\"\r\nMessageBody = \"{%}tBody{%}\"\r\n\r\nSet ol = WScript.CreateObject(\"Outlook.Application\")\r\nSet ns = ol.getNamespace(\"MAPI\")\r\nns.logon \"\",\"\",true,false\r\nSet newMail = ol.CreateItem(olMailItem)\r\nnewMail.Subject = MessageSubject\r\nnewMail.Body = MessageBody & vbCrLf\r\n\r\n' validate the recipient, just in case...\r\nSet myRecipient = ns.CreateRecipient(ToAddress)\r\nmyRecipient.Resolve\r\nIf Not myRecipient.Resolved Then\r\nMsgBox \"unknown recipient\"\r\nElse\r\n newMail.Recipients.Add(myRecipient)\r\n newMail.Send\r\nEnd If\r\n\r\nSet ol = Nothing" Encoding="0"/> <WAIT FOR WINDOW TITLE Title="Choose Profile" Partial="FALSE" Wildcards="FALSE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="10"/> <TEXT TYPE Action="0" Text="<ENTER>"/> And here's the VBS script: ========================= = Dim ToAddress Dim MessageSubject Dim MessageBody Dim MessageAttachment Dim ol, ns, newMail ToAddress = "abc@xyz.com" ' Change this to your own address to test MessageSubject = "Test using VBS" MessageBody = "{%}tBody{%}" Set ol = WScript.CreateObject("Outlook.Application") Set ns = ol.getNamespace("MAPI") ns.logon "","",true,false Set newMail = ol.CreateItem(olMailItem) newMail.Subject = MessageSubject newMail.Body = MessageBody & vbCrLf ' validate the recipient, just in case... Set myRecipient = ns.CreateRecipient(ToAddress) myRecipient.Resolve If Not myRecipient.Resolved Then MsgBox "unknown recipient" Else newMail.Recipients.Add(myRecipient) newMail.Send End If Set ol = Nothing
  20. Thanks Cory, interesting idea. As per my reply to Alan, I’ve decided to tolerate the untidiness until the project is completely finished.
  21. Thanks Thanks Alan. I’ve always found that handy myself but I’ll see if unchecking makes the subject task any easier. When developing a complex macro like this one, it’s useful that when routinely saving it MEP pops up a series of warnings and tapping Y to each very quickly gets the undefined variables setup. BTW, I can’t test the following right now (posting from my iPad), but I think I’m right that I can confine my task to the main macro? IOW, even if all the many of the submacros it calls have their necessary variables defined (as well as unnecessary ones), the main macro must also have these defined too? Anyway, I’ve decided to postpone this ‘housekeeping’ until the entire project is finished!
  22. This version accepts a set of numbers, each of any length (well, under a billion!) separated by single spaces. I've just used a small test set, so add whatever input method suits, such as a prompt or imported text file etc. If you have difficulty understanding what's going on, sprinkle with Text Box Displays to show the changing values of key variables. It would be a mere three lines of script without that final 'and'! Variable Set String %tRawInput% to "1 23 456 7 8 999" // Test input Variable Modify String: Replace " " in %tRawInput% with ", " Variable Set Integer %nLenRaw% to the length of variable %tRawInput% Repeat Until %tChar% Contains "," Variable Modify String: Copy part of text in %tRawInput% starting at %nLenRaw% and 1 characters long to %tChar% Variable Modify Integer %nLenRaw%: Decrement End Repeat Variable Modify Integer: %nLenRaw% = %nLenRaw% + 2 Variable Modify String: Copy part of text in %tRawInput% starting at %nLenRaw% and 10 characters long to %tEnd% Variable Modify String: Delete part of text from %tRawInput% starting at %nLenRaw% and 10 characters long Variable Modify String %tRawInput%: Append Text ( and) Variable Modify String %tRawInput%: Append Text String Variable (%tEnd%) Text Box Display: RESULT <VARIABLE SET STRING Option="\x00" Destination="%tRawInput%" Value="1 23 456 7 8 999" NoEmbeddedVars="FALSE" _COMMENT="Test input"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%tRawInput%" ToReplace=" " ReplaceWith=", " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE"/> <VARIABLE SET INTEGER Option="\x0D" Destination="%nLenRaw%" Text_Variable="%tRawInput%"/> <REPEAT UNTIL Variable="%tChar%" Condition="\x06" Value=","/> <VARIABLE MODIFY STRING Option="\x09" Destination="%tChar%" Variable="%tRawInput%" Start="%nLenRaw%" Count="1" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY INTEGER Option="\x08" Destination="%nLenRaw%"/> <END REPEAT/> <VARIABLE MODIFY INTEGER Option="\x00" Destination="%nLenRaw%" Value1="%nLenRaw%" Value2="2"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%tEnd%" Variable="%tRawInput%" Start="%nLenRaw%" Count="10" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY STRING Option="\x0A" Destination="%tRawInput%" Start="%nLenRaw%" Count="10"/> <VARIABLE MODIFY STRING Option="\x06" Destination="%tRawInput%" Value=" and" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY STRING Option="\x07" Destination="%tRawInput%" Variable="%tEnd%" NoEmbeddedVars="FALSE"/> <TEXT BOX DISPLAY Title="RESULT" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %tRawInput%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
  23. Hi Alan, Minor point: I'd place %Results% in the body of the display, not the header, which will only accommodate a small number of digits. <TEXT BOX DISPLAY Title="RESULTS" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %tResults%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
×
×
  • Create New...