简体   繁体   中英

difficulty in creating an icon that can be sized

I am using the combination of:

    Application.DocumentExport SaveFileName, pjPDF, FromDate:=EarliestStart-30, ToDate:=LFin+30

    and

    xlbook.activesheet.OLEObjects.Add(FileName:="C:\Macros\Target-" & t & ".pdf", Link:=False, _
    DisplayAsIcon:=True, IconFileName:= _
    "C:\windows\Installer\{AC76BA86-1033-FFFF-7760-0E0F06755100}\_PDFFile.ico", _
    IconIndex:=0, IconLabel:="Target-" & t, Left:=1082, Top:=TOffset, Width:=5, Height:=5).Select

   xlbook.activesheet.OLEObjects.Placement = 1                            'Move and Size with cells

with the intention of placing an icon on an excel worksheet in a specific cell. When run with these commands, I get a square Icon, measuring about 50 x 50 points with the acrobat symbol displayed above the text ie "189.PDF, identified as the IconLabel above. I am trying to size the icon to be 8 x 18 points so it fits inside the cell, which measures 10 x 20 points. I would prefer not to also display the Acrobat picture, jut the IconLabel text.

The Application.DocumentExport command above works exactly as it shot, saving a copy of the pdf source to a pdf, even if many pages long.

The OLEObjects.Add command works, but does not allow me to resize the icon so it will fit within the excel cell where I want to place it.

TOffset is the sum of the points from the top of the excel page to the top of the cell that I want to place the icon into. Width and Height above are supposed to represent size values in points for the Icon, but they do not work, either with or without the .OLEObjects.Placement command above.

I tried running the same 2 commands but leaving out the IconIndex field and value out of the OLEObjects string of commands. This produced desired rectangular boxes of the desired dimensions but caused some internal excel issues with being able to save the excel file--- the app did not allog me to save the file due to severe damage to the excel file. I traced the error to not having the IconIndex fieldname in the OLEObjects string. IconIndex is shown to be an optional entry on the OLEObjects.Add Microsoft page If I assign the IconValue any integer value other than 0, then the icon is created as clear but the dimensions are the same as if IconIndex:=0.

The end goal is to take the saved PDF and place an icon holding the copy of the pdf file into a specific cell on the excel worksheet that operates similar to a button and allows me to write a short identifier to the caption for the icon.

The end result is a standalone workbook that can be distributed with need to also copy/paste all of the pdf's created by the application with it.

Would be appreciative for some leads as to how I can resize the icons, use buttons instead of OLEOPbjects.add, etc. I have tried hyperlinks, but then I have a large workbook of many, many sheets, each holding a single PDF. What I want in the end is a single worksheet which I can use to hold PDF's within Icons for all of the different printouts I have created.

Thanks

Dim TOffset As Integer

xlbook.Sheets("Task Graphics").Select

With xlbook.ActiveSheet
    .Range("B2").Select
    TOffset = .Range("A1:A" & row - 3).Height - 11
    .Cells(row - 3, 18) = Format(LFin - 30, "mm/dd/yy")

    .OLEObjects.Add(FileName:="C:\Macros\Target-" & t & ".pdf", Link:=False, _
     DisplayAsIcon:=True, IconFileName:= _
    "C:\windows\Installer\{AC76BA86-1033-FFFF-7760-0E0F06755100}\_PDFFile.ico", _
    IconIndex:=0, IconLabel:="Target-" & t, Left:=1080, Top:=TOffset).Select

    .OLEObjects.Placement = 1
    .OLEObjects.ShapeRange.LockAspectRatio = msoFalse
    .OLEObjects.Width = 14
    .OLEObjects.Height = 10
    sbDeleteAFile (SaveFileName)
 End With

This answer positions the icon on the left side of the cell, leaving space in the same cell to enter some text (LFin-30), which is a date. Not sure why I had to separate the Width and Height declarations separately from the OLEObjects statement, as the OLEObjects.add reference displays that Width and Height are properties of the Icon.

在此处输入图片说明

The only issue I have remaining with this is that when you click the icon, the "edit" symbols (the four corners of the icon have edit circles) and if you drag the icon at all, it may resize.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM