export in excel and lock cells

Icarus84

Registered User.
Local time
Today, 05:56
Joined
May 14, 2013
Messages
17
Hi all
I need your help to insert the code that is blocking the cells from the exported excel with the range B1:BB800. :banghead:
Below i have the macro code for the export:
Function invoice()
On Error GoTo invoice_Err
DoCmd.OutputTo acOutputQuery, "Export", "MicrosoftExcelBiff8(*.xls)", "C:\Access\Export.xls", True, "", 0, acExportQualityPrint
Beep
MsgBox "DONE", vbOKOnly, ""

invoice_Exit:
Exit Sub

Wait for your help :)
 
this code will export to cell A1.
If you want to export to anthing other, then
either:
import in Excel from access using COPYFROMRECORDSET
(you can tell it where to post the recset)

or
export from Access to excel using object control to take control of excel
Code:
  'you must add the Excel reference in VBE menu: tools, references.
 Dim xl As Excel.Application
Dim sSht As String
Dim rst as recordset
 set rst = currentdb.openrecordset("myQuery")
 Set xl = CreateObject("excel.application")
With xl
   .Visible = True
    .Workbooks.Open vFile
      .Range("B2").CopyFromRecordset rst
    .ActiveWorkbook.save
   .Quit
End With
 Set xl = Nothing
Set rst = Nothing
 

Users who are viewing this thread

Back
Top Bottom