Excel Margins
Excel Margins
Excel Margins
Excel Margins
Excel Margins
Excel Margins Excel Margins Excel Margins Excel Margins Excel Margins Excel Margins Excel Margins Excel Margins
Excel Margins Excel Margins
Excel Margins
Go Back  Xtreme Visual Basic Talk > > > Excel Margins


Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2010, 04:49 AM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,795
Default Excel Margins


Hi There,

This is driving me nuts!

I'm Automating Excel through a class I have built but the margin's do not correspond to what I want for example if I set the left margin to 2.1 I figured out that by using this (value / 0.1) * 2.83464567 it displays a left margin at 2.1 in the Pagesetup, I know this cannot be correct coding?

I've tried Application.InchesToPoints but again that produces incorrect results

Code:
Public Property LeftMargin() As Single Get Return mSheet.PageSetup.LeftMargin End Get Set(ByVal value As Single) mSheet.PageSetup.LeftMargin = (value / 0.1) * 2.83464567 End Set End Property

any advice



Edit by Moderator:
Thread moved from Excel VBA forum to VB .Net Office Automation forum.

Last edited by Colin Legg; 06-06-2010 at 12:21 PM.
Reply With Quote
  #2  
Old 06-07-2010, 07:13 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Hi PiggyBank,

By dividing by 0.1 and then multiplying by 2.83464567, you are effectively multiplying by 28.3464567.

I don't know what trouble that you are having on your system, but on mine, using Excel.Application.InchesToPoints returns a value of 72 when passed in 1 and does do the correct conversion.

So, for me, the following works fine:

Code:
Public Property LeftMargin() As Single
   Get
      Return mSheet.PageSetup.LeftMargin / _
          mSheet.Application.InchesToPoints(1)
   End Get
   Set(ByVal value As Single)
      mSheet.PageSetup.LeftMargin = value * _
          mSheet.Application.InchesToPoints(1)
   End Set
End Property
Give it a try and let us know how it goes...

- Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
Reply

Tags
automation, excel, left margin, leftmargin, margin


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Excel Margins
Excel Margins
Excel Margins Excel Margins
Excel Margins
Excel Margins
Excel Margins Excel Margins Excel Margins Excel Margins Excel Margins Excel Margins Excel Margins
Excel Margins
Excel Margins
 
Excel Margins
Excel Margins
 
-->