Ouput changing column properties using a module

M

Mike

I have coded using VBA to output a query to a sheet in a protected workbook
and it works fine. I added code to output a 2nd query to another sheet in
the same workbook and when it runs it causes various columns on the first
sheet to change from their format to a date format. If I comment out the
code to output to the 2nd sheet the first sheet goes back to normal.

Here is the code I am using for outputting to the 2nd sheet:

' Write the data to the Termed Detail worksheet.
Set objSht = objWkb.Worksheets("TermedDetails")
objSht.Range("A2").CopyFromRecordset rs1
 
P

Pendragon

I just ran into something similar and here is how I fixed it. Using your code,

objSht.Select
ActiveSheet.Range("A2").CopyFromRecordset rs1

Apparently, just naming the sheet in your SET statement doesn't actually
activate/select the sheet.
 
D

Douglas J. Steele

Alternatively,

With objWkb.Worksheets("TermedDetails")
.Range("A2").CopyFromRecordset rs1
End With
 
M

Mike

Pendragon,
By just adding the objSht.Select it cured the problem. This was a
great help.

Thanks.
 

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