saving cell format in excell sheet

hi
i'm posting my sales transactions in ms access
but i need to print a summary in excell sheet daily basis
i format one excel sheet ( borders , colours , fonts ,, etc ) to be ok for the print out
then , i have  to export from ms access query to the  excell sheet
but always i have to again adjust the format of the excell sheet
is there any way or any macro to save the format of excell sheet
NiceMan331Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
This really depends on a LOT of factors, and you need to provide a lot of details (how/what/who is the export done? what happens with your layout after it is imported? What changed to what ? etc etc)
For now, my gut tells me you should import it to a temp excel file, and then load this temp excel file into an the excel file WITH the correct layout, and macro (which only imports the text from the excel file, as text shouldn't adjust your layout except for normal boundaries).
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You could save that Excel file as a Template, and then use the Template when creating a new Excel file for your report. I'm not sure how you're creating the Excel file, so can't help much more with that. If you could post code that shows what you're doing, we might be able to offer more specific advice.
0
NiceMan331Author Commented:
i'm not using any code for the export . i'm just using ms access wizard to export query output to ms excell
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Rey Obrero (Capricorn1)Commented:
will the headers of the excel file be always the same ?
if it is, you can simply export the information to excel using the CopyFromRecordset function

Sub export2XL()
dim rs as dao.recordset, xlObj as object
set rs=currentdb.openrecordset("yourQuery")

set xlObj=createobject("excel.application")
      xlObj.workbooks.add <path to template>\yourtemplate.xltx"
      xlobj.range("A2").copyfromrecordset rs
      xlObj.activeworkbook.saveas "c:\mydocuments\newFile.xlsx"
     xlObj.quit
rs.close
end sub
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
i'm not using any code for the export
Then you'll need to change your process. As Rey has shown, you can use CopyFromRecordset.
0
NiceMan331Author Commented:
will the headers of the excel file be always the same ?
yes



     
xlObj.workbooks.add <path to template>\yourtemplate.xltx"
you mean the pre formatted sheet ?

   
 xlobj.range("A2").copyfromrecordset rs
shall i determine A2:M20 if my templete in this range ?

   
 xlObj.activeworkbook.saveas "c:\mydocuments\newFile.xlsx"
which new file ?
0
Rey Obrero (Capricorn1)Commented:
<which new file ? > new file is the name you will give to the excel file with the new records

<shall i determine A2:M20 if my templete in this range ?> No need to determine, since your columns does not change, last column is M, you can delete the contents with

.range("A2:M100").clearcontents

xlobj.range("A2").copyfromrecordset rs  >>> will copy the whole recordset starting at A2


<you mean the pre formatted sheet ? > yes, normally you should save this  fiel as a template, extension  .XLTX
0
NiceMan331Author Commented:
<which new file ? > new file is the name you will give to the excel file with the new records
sorry i confused here  , you mean this code will copy the query to a new file first ? ,or directly to my templete ?
sorry again
0
Rey Obrero (Capricorn1)Commented:
when you open the template, you will create a new workbook
the records will be copied to the new workbook, then you have to save the workbook with this code

  xlObj.activeworkbook.saveas "c:\mydocuments\newFile.xlsx"

to the folder c:\mydocuments (which you can change)
and with a excel filename newFile.xlsx, newfile.xlsx could be any name you want to be the name of the newly created excel file
0
NiceMan331Author Commented:
i have 2 issues here
1- i designed the templete as what i need
2-when it copied , the columns not copied in same order of the query , because some columns formatted as date , some as number ,, etc
i want to investigate first the normal copy ( without templete ) to see is will copied in same column order or not , what is the code will be ?
0
NiceMan331Author Commented:
oh , the mistake in my query itself
it is ok now for ordering
remaining 2 things :
1- the raw height in the new book not coming as same the templete
2-some clomuns only which formatted as number , not coming in same format
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
1 - What do you mean by "raw height"?

2 - Did you set the formatting in the Column in your Excel template? If not, please explain further, with examples.
0
NiceMan331Author Commented:
1 - What do you mean by "raw height"?
sorry , row height

Did you set the formatting in the Column in your Excel template?
yes i did
for example one column formatted as number with 2 dicimal places , then after copy , it becomes with more than 2 dicimal places , where i have to adjust it manually
0
Rey Obrero (Capricorn1)Commented:
upload a copy of your template and a copy of the db.
0
NiceMan331Author Commented:
ok
tomorrow i will
thanx
0
NiceMan331Author Commented:
give me chance till tomorrow also , because i'm trying to adjust the format of my db
if not success , i will send it
by the way , if you please answer my other question
http://www.experts-exchange.com/Database/MS_Access/Q_28580925.html
the solution there may be like this way , i think to copy the query to an existing excel sheet
with pre define of weeks range in excell
but i need to adjust the code there , instead of using templete , i want to copy it directly to an existing sheet
0
Rey Obrero (Capricorn1)Commented:
i can post a solution to that thread if you can provide the information from the table, query

in short, i need a db to play with..  with the tables/query "WeekAvg"
0
NiceMan331Author Commented:
Ok،I will
0
NiceMan331Author Commented:
rey
i reveiewed my query , i found my mistake , i were format calculated number like this
format = standar
input mask = 0
when i removed the 0 , it become ok
now it is ok , except this 2 things
1- how to open the templete excel to adjust it in the future instead of creating new one
2-how to adjust the code , if i want to select copy the data from my query to an existing sheet ( not to craete new one with templete formatted one )

thanx
0
Rey Obrero (Capricorn1)Commented:
Sub export2XL()
dim rs as dao.recordset, xlObj as object
set rs=currentdb.openrecordset("yourQuery")

set xlObj=createobject("excel.application")

 'open existing excel file
      xlObj.workbooks.open "c:\folderName\MyExcel.xlsx"
'show the open excel
      xlObj.visible=true
'select the sheet
      xlObj.worksheets("NameOfSheet").select
'copy the recordset
      xlobj.range("A2").copyfromrecordset rs
'save the workbook
      xlObj.activeworkbook.save
     xlObj.quit
rs.close
end sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NiceMan331Author Commented:
great
i think it will be helpful
i will try it
thanx
0
Rey Obrero (Capricorn1)Commented:
how about the sample data for your other thread?
0
NiceMan331Author Commented:
YES OK
it is ok
saturday , i will upload the db for the other question
thanx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.