Avatar of NiceMan331
NiceMan331
 asked on

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
Microsoft AccessMicrosoft ExcelSpreadsheets

Avatar of undefined
Last Comment
NiceMan331

8/22/2022 - Mon
Kimputer

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).
Scott McDaniel (EE MVE )

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.
NiceMan331

ASKER
i'm not using any code for the export . i'm just using ms access wizard to export query output to ms excell
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Scott McDaniel (EE MVE )

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.
NiceMan331

ASKER
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 ?
Rey Obrero (Capricorn1)

<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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
NiceMan331

ASKER
<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
Rey Obrero (Capricorn1)

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
NiceMan331

ASKER
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 ?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
NiceMan331

ASKER
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
Scott McDaniel (EE MVE )

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.
NiceMan331

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rey Obrero (Capricorn1)

upload a copy of your template and a copy of the db.
NiceMan331

ASKER
ok
tomorrow i will
thanx
NiceMan331

ASKER
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
https://www.experts-exchange.com/questions/28580925/adding-another-column-head-to-cross-tab-query.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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Rey Obrero (Capricorn1)

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"
NiceMan331

ASKER
Ok،I will
NiceMan331

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
NiceMan331

ASKER
great
i think it will be helpful
i will try it
thanx
Rey Obrero (Capricorn1)

how about the sample data for your other thread?
NiceMan331

ASKER
YES OK
it is ok
saturday , i will upload the db for the other question
thanx
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck