0

I'm having an issue and dont know if this is possible to be done.

I need to insert a string variable through another macro that is protected and can't access the VBA code.

At my code, I intend to send a string when call the protected macro (with application.run "macroname"). This protected macro prompts a selection window to select a file. I pretend to automatically insert at macro's prompt my string and send "ENTER" command to open the desire file.

Is this possible to be done?

laylarenee
  • 3,276
  • 7
  • 32
  • 40
Jsilva
  • 1
  • 2
  • While it is possible to use the `sendkeys` command to send keystrokes, it likely won't work. Why don't you just [crack](http://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project) the VBA project's password and edit the macro? – vacip Sep 15 '15 at 11:06
  • 1
    @vacip the first questions should be why is it protected? Maybe its an bought add-in or something similar. Suggesting to go and crack that at will isn't the right choice. – DragonSamu Sep 15 '15 at 11:16
  • @DragonSamu True. So, Jsilva, if you have bought this VBA addin, then ask the developer to add this feature for you. (You mentioned VBA, so I assume this is a VBA addin, not a COM one, which suggests a small, individual developer, or in-company development.) If a collegue created this macro, ask him to add the feature or give you the code. If all else fails, check the license agreement and your country's legal system, and crack the VBA project if you are legally allowed to do so. – vacip Sep 15 '15 at 12:43
  • I could crack it, but how? – Jsilva Sep 15 '15 at 18:06
  • C'mon, man... I have linked the related stackoverflow discussion in my first comment. [But here it is again, click here!](http://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project) – vacip Sep 18 '15 at 12:16

1 Answers1

-1

If I understood you correctly, this is what you are looking for:

1) Locked workbook (VBA module is protected) contains e.g. the following macro:

Public Sub Test(sInput As String)
    ActiveCell.Value = sInput
    MsgBox sInput
End Sub

What you are trying to do, is to call this Test macro, but you don't know how to pass parameter (correct me if I got this wrong).

This is how you do it:

Sub RunProtectedMacro()
    Dim vResult As Variant
    vResult = Application.Run("'" & LockedWorkbook.Name & "'!Test", "some string argument")
End Sub
Robert J.
  • 2,631
  • 8
  • 32
  • 59
  • 1
    The OP is trying to place a `String` into an `InputBox` or `UserForm` that runs inside the protected vba module/add-in thus you can't just parse information to it. Unless you would exactly know how its coded. – DragonSamu Sep 15 '15 at 15:55
  • Yes, that is right. I already tried to pass an argument, but that doesn't work. The protected macro opens a window to browse a file. What i need to do is place the variable into the select input box. – Jsilva Sep 15 '15 at 18:10