Is it Possible to Convert VBA to VB

R

Revolution

Dear All,

I planned to write a code which will automatically set a random password.
For that first I used the macro and I copied the code from VBA to VB but it
won't work properly. I added the following references Microsoft Office
Library and Microsoft Excel Library.

while executing code I faced this error message "Object Variable or With
block variable not set"

Please explain why it is happening I need to follow any other steps to do
before coping the code.

Here is the code from VBA..
-------------------------------

Sub file (pwd As String, filename As String)

' file Macro
' Macro recorded 12/26/2005 by Revolution

ActiveWorkbook.SaveAs FileName:=filename, _
FileFormat:=xlNormal, Password:=pwd, WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub
---------------------------------------

In the ActiveWorkbook it gives the Error message

Please let me know u need some other information

Waiting for ur reply
 
T

TC

The symbol "ActiveWorkbook" refers to the currently open active
workbook - when you use that symbol from within Excel VBA.

But how could that possibly happen from within a VB program? How does
the VB program know what workbook you are talking about? Have you done
anything in the VB program to open the relevant Excel file?

If I understand what you're trying to do, the VB program will have to
open the relevant workbook & get a runtime reference to it. Something
like this:

(untested)

dim oExcel as object, oWorkbook as object

' start a copy of Excel.
set oExcel = createobject ("Excel.Application")

' open the relevant file and get a runtime reference to it.
set oWorkbook = oExcel.open "<full path to your excel file>"

then use "oWorkbook" in place of "ActiveWorkbook".

Or something like that.

HTH,
TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top