Solved

saving cell format in excell sheet

Posted on 2014-12-15
23
215 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 84
Comment Utility
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
Comment Utility
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
Comment Utility
upload a copy of your template and a copy of the db.
0
 

Author Comment

by:NiceMan331
Comment Utility
ok
tomorrow i will
thanx
0
 

Author Comment

by:NiceMan331
Comment Utility
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
Comment Utility
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
Comment Utility
Ok،I will
0
 

Author Comment

by:NiceMan331
Comment Utility
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
Comment Utility
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
Comment Utility
great
i think it will be helpful
i will try it
thanx
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
how about the sample data for your other thread?
0
 

Author Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now