0

I have been trying how to figure this out for awhile now. I locked my vba project, because I don't want most people to be able to altered the code. The problem is, I have code that modifies other modules based on user input, this obviously would cause a problem as, you cannot modify a module if it is locked. Being how I just don't do 'sendkeys' (lol c'mon), there is no practical way to unlock it so I can modify the code.

So I created an .xlam add-in. The module writes the new code to file, saves it as a .bas type, then the add-in imports and runs it.

But...

I am having trouble interacting with the workbook (the one that generated the module for the .xlam add-in). Below are the portions of the code that I am finding tricky. It is primarily related to performing autofill and updating a form with said workbook.

public sub wbUpdate()
    Dim wb as workbook
    Set wb = workbooks("WB.xlsm")
    Dim lastRow as long

    '======example #1====== not sure my autofill syntax is right:
    Worksheets("Sheet1").Select
    lastRow = wb.worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).row
    k = lastRow
    wb.worksheets("Sheet1").Range("B2").Select
    wb.worksheets("Sheet1").Range("B2").value = ""

    'below is where I get a runtime error, not sure why
    wb.worksheets("sheet1").Range("B2").AutoFill _ 
        Destination:=wb.worksheets("Sheet1").Range("B2:B" & lastRow)

    '======Example #2====== Try to show a userForm and center
    'but can't seem to get the syntax right

    With wb.progressBar '<== runtime error on @ this line
        .StartUpPosition = 0
        .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
        .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
        .Show
    End With
End Sub

These are the primary issues. Personally, I would rather just run code directly from the worksheet (in other words think of a module executing what something in say Range("A1") - like "msgbox someString") but I am not sure if this is even possible. Been wondering this one for quite awhile

Any pointers on what the syntax should be for example #1 and #2 -- And/Or ideas on how to execute code directly from a sheet, thereby bypassing the headache all together?

Vin
  • 10,517
  • 10
  • 58
  • 71
Singularity20XX
  • 321
  • 5
  • 20

0 Answers0