Avatar billede hyperactive Nybegynder
31. december 2002 - 13:10 Der er 1 løsning

Definere størrelsen på labels genereret i word via ASP

Jeg har fundet denne kode på adressen: http://support.microsoft.com/default.aspx?scid=kb;en-us;285176


<%@ Language=VBScript %>
<HTML>
<BODY>
<SCRIPT LANGUAGE=VBScript>
Sub CreateDataDoc(oApp)
  ' Declare variables.
  Dim sServer,oDoc,oRS,sTemp,sHead,oRange,oField
 
  ' Place your server's name here.
  sServer = "localhost"
  ' Create a new document.
  Set oDoc = oApp.Documents.Add
  ' Create a new recordset.
  Set oRS = CreateObject("ADODB.Recordset")
  ' Open the XML recordset from the server and pass the SQL statement
  ' to the Getdata.asp page.
  sSQL = "SELECT * FROM ordrer"
  oRS.Open "http://" & sServer & "/WordMailMerge/Getdata.asp?SQL=" & sSql
  ' Convert the recordset to a string.
  sTemp = oRS.GetString(2, -1, vbTab)  ' 2 = adClipString
       
  ' Append the field names to the front of the string.
  For Each oField In oRS.Fields
    sHead = sHead & oField.Name & vbTab
  Next
       
  ' Strip off the last tab.
  sTemp = Mid(sHead, 1, Len(sHead) - 1) & vbCrLf & sTemp
       
  ' Get a range object and insert the text into the document.
  Set oRange = oDoc.Range
  oRange.Text = sTemp
 
  ' Convert the text to a table.
  oRange.ConvertToTable vbTab
  ' Save the document to a temp file.
  oDoc.SaveAs "C:\data.doc"
  ' Close the document (no save).
  oDoc.Close False
End Sub


Sub ButtonClick()
  Dim oApp
  Dim oDoc
  Dim oMergedDoc
 
  ' Create an instance of Word.   
  Set oApp = CreateObject("Word.Application")

  ' Create our data file.
  CreateDataDoc oApp
 
  ' Add a new document.
  Set oDoc = oApp.Documents.Add
  With oDoc.MailMerge
    ' Add our fields.
    .Fields.Add oApp.Selection.Range, "fornavn"
    oApp.Selection.TypeText " "
    .Fields.Add oApp.Selection.Range, "efternavn"
    oApp.Selection.TypeParagraph
    .Fields.Add oApp.Selection.Range, "adresse"
    oApp.Selection.TypeText ", "
    .Fields.Add oApp.Selection.Range, "postnr"
    oApp.Selection.TypeParagraph
    .Fields.Add oApp.Selection.Range, "bynavn"
    oApp.Selection.TypeParagraph
         
    ' Create an autotext entry.
    Dim oAutoText
    Set oAutoText = oApp.NormalTemplate.AutoTextEntries.Add _
    ("MyLabelLayout", oDoc.Content)
    oDoc.Content.Delete
    .MainDocumentType = 1  ' 1 = wdMailingLabels
       
    ' Open the saved data source.
    .OpenDataSource "C:\data.doc"

    ' Create a new document.
    oApp.MailingLabel.CreateNewDocument "5160", "", _
        "MyLabelLayout", , 4  ' 4 = wdPrinterManualFeed

    .Destination = 0  ' 0 = wdSendToNewDocument
    ' Execute the mail merge.
    .Execute

    oAutoText.Delete
  End With
     
  ' Close the mail merge edit document.
  oDoc.Close False
  ' Get the current document.
  Set oMergedDoc = oApp.ActiveDocument
  ' Show Word to the user.
  oApp.Visible = True
 
  ' Uncomment these lines to save the merged document locally.
  'oMergedDoc.SaveAs "C:\test.doc"
  'oMergedDoc.Close False
  'oApp.Quit False
End Sub
</SCRIPT>
<INPUT type=button value="Create Word Document" onclick="VBScript:ButtonClick">
</BODY>
</HTML>

Det fungerer fint, bortset fra at labelstørrelsen i det genererede word dokument ikke er rigtig.... Jeg ønsker at bruge den størrelse der hedder Avery C2163 (9,9 x 3,81 cm)... Hvordan definerer jeg dette i min kode???
Avatar billede hyperactive Nybegynder
31. december 2002 - 13:22 #1
Har fundet ud af det..... Ændrede blot "5160" til det rigtige navn.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester