Solved

saving cell format in excell sheet

Posted on 2014-12-15
23
217 Views
Last Modified: 2014-12-18
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
0
Comment
Question by:NiceMan331
  • 12
  • 7
  • 3
  • +1
23 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 40500028
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
 
LVL 84
ID: 40500044
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
 

Author Comment

by:NiceMan331
ID: 40500122
i'm not using any code for the export . i'm just using ms access wizard to export query output to ms excell
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 500 total points
ID: 40500332
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
 
LVL 84
ID: 40500363
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
 

Author Comment

by:NiceMan331
ID: 40500770
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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40500852
<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
 

Author Comment

by:NiceMan331
ID: 40500934
<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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40500966
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
 

Author Comment

by:NiceMan331
ID: 40502104
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
 

Author Comment

by:NiceMan331
ID: 40502141
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 84
ID: 40502282
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
 

Author Comment

by:NiceMan331
ID: 40502397
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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40502526
upload a copy of your template and a copy of the db.
0
 

Author Comment

by:NiceMan331
ID: 40503128
ok
tomorrow i will
thanx
0
 

Author Comment

by:NiceMan331
ID: 40504526
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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40504540
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
 

Author Comment

by:NiceMan331
ID: 40504556
Ok،I will
0
 

Author Comment

by:NiceMan331
ID: 40506664
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
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40506816
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
 

Author Comment

by:NiceMan331
ID: 40506822
great
i think it will be helpful
i will try it
thanx
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40506828
how about the sample data for your other thread?
0
 

Author Comment

by:NiceMan331
ID: 40506832
YES OK
it is ok
saturday , i will upload the db for the other question
thanx
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now