Refer to workbook

A

Arne Hegefors

Hi! I have a workbook that I have set as an object by reffering to active
workbook. Then I want to save that workbook but I cannot refer to active
workbook because another workbook is active. Please help me!

Dim oPosFile As Object
Set oPosFile =
Workbooks(ActiveWorkbook.Name).Sheets(ActiveSheet.Name)

'''
ActiveWorkbook.SaveAs Filename:= _
sRMPosSaveFilePath & sRMPosFilename & ".txt",
FileFormat:=xlText _
, CreateBackup:=False
 
B

broro183

Hi Arne,

I recommend changing oPosFile declaration from an obect variable to a
workbook variable, this will allow "intellisense" to work (ie the VBE will
recgnise what oPosFile is & can make appropriate suggestions for possible
properties &/or methods).
Does the below work for you?

Dim oPosFile As workbook
Set oPosFile = thisworkbook
'...
oPosFile.SaveAs Filename:= _
sRMPosSaveFilePath & sRMPosFilename & ".txt",
FileFormat:=xlText _
, CreateBackup:=False

hth
Rob

__________________
Rob Brockett
NZ
Always learning & the best way to learn is to experience...
 

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