Avatar billede overgreat Forsker
13. juli 2010 - 11:33 Der er 4 kommentarer og
1 løsning

gemme fil under bestemt navn

hej jeg har denne kode.

Mit store ønske er at navnet på filen bliver "tekst fra første markederede celle".htm

Håber I kan trylle.

Lige nu er den: PageName = "C:\Users\hov\Desktop\COMENXA\Personlig xls\produkt.htm"

------

Option Base 1 ' sets first array element to 1, not 0
Sub MakeHTM()
' This macro was originally written by Chris Mead (www.meadinkent.co.uk)
' You are free to use it for private use provided this copyright message is left unchanged.

Dim PageName As String, FirstRow As Integer, LastRow As Integer
Dim FirstCol As Integer, LastCol As Integer, MyBold As Byte, MySize As Integer
Dim TempStr As String, MyRow As Integer, MyCol As Integer, InsideTD As String
Dim MyFormats As Variant, Vtype As Integer, DefFontSize As Integer
Dim MergeCount As Integer, MyCell As Range, HL_Locn As String
Dim MyWidths() As Single, TotWidth As Single

' MyFormats is an array which can contain formats for numbers and dates. Add one element for each table column.
MyFormats = Array("#", "", "£#,##0.00;(£#,##0.00)", "£#,##0.00;(£#,##0.00)", "", "0.0%;(0.0%)")
DefFontSize = 10 ' this is the default size on the spreadsheet. Text which is larger or smaller will be modified
PageName = "C:\Users\hov\Desktop\COMENXA\Personlig xls\produkt.htm" 'location and name of Saved file
HL_Locn = "e1"  ' location on worksheet for a hyperlink
FirstRow = 1 ' *** the range of the worksheet to be  ***
LastRow = 100 ' *** converted into an HTML table      ***
FirstCol = 1
LastCol = 2

If UBound(MyFormats) < (LastCol - FirstCol + 1) Then
MsgBox "The 'MyFormats' array has insufficient elements", vbOKOnly + vbCritical, "MakeHTM macro (CiM)"
Exit Sub
End If
ReDim MyWidths(LastCol)
For MyCol = FirstCol To LastCol
    MyWidths(MyCol) = Cells(FirstRow, MyCol).ColumnWidth
    TotWidth = TotWidth + MyWidths(MyCol)
Next

' --- You may choose to modify the title and heading ---
Open PageName For Output As #1
' --- end of hard coded header section ---

Print #1, "<table>"
Print #1, "<tr height='1'>"    'an initial row to set col widths to those on the worksheet
For MyCol = FirstCol To LastCol
Print #1, "<td width='" & Format(MyWidths(MyCol) / TotWidth, "#%") & "'>&nbsp;</td>"
Next MyCol
Print #1, "</tr>"
For MyRow = FirstRow To LastRow
Print #1, "<tr>"
MyCol = FirstCol
Do While MyCol <= LastCol
Set MyCell = Cells(MyRow, MyCol)    ' sets variable to the current cell

MyBold = 0
MySize = 0
If MyCell.Font.Bold = True Then MyBold = 1
If MyCell.Font.Size > DefFontSize Then MySize = 1
If MyCell.Font.Size < DefFontSize Then MySize = 2

Vtype = 0 ' check whether the cell is numeric
If IsNumeric(MyCell.Value) Then Vtype = 1
If IsDate(MyCell.Value) Then Vtype = 2

If "-" & MyCell.Value & "-" = "--" Then
TempStr = "&nbsp;"  ' a space character to be entered in empty cells
Else

    ' if numeric and a format code has been created, apply it
    If Vtype > 0 And MyFormats(MyCol - FirstCol + 1) <> "" Then
    TempStr = Format(MyCell.Value, MyFormats(MyCol - FirstCol + 1))
    Else
    TempStr = MyCell.Value
    End If
   
    If MyBold = 1 Then
    TempStr = "<b>" & TempStr & "</b>"
    End If
    If MySize = 1 Then
    TempStr = "<big>" & TempStr & "</big>"
    End If
    If MySize = 2 Then
    TempStr = "<small>" & TempStr & "</small>"
    End If
    If MyCell.Font.ColorIndex <> 1 And MyCell.Font.ColorIndex <> -4105 Then
    TempStr = "<font color='" & GetRGB(MyCell.Font.Color) & "'>" & TempStr & "</font>"
    End If

End If

'if cells are merged, count the number of columns. If not merged it will return 1
MergeCount = MyCell.MergeArea.Columns.Count
InsideTD = ChkBorders(MyRow, MyCol) ' a function in this module to set Border commands

If MergeCount > 1 Then
    InsideTD = InsideTD & " align='center' colspan='" & Format(MergeCount, "#") & "'"
    MyCol = MyCol + MergeCount - 1
Else
    If Vtype = 1 And InStr(InsideTD, "align") = 0 Then InsideTD = InsideTD & " align='right'"
End If

TempStr = "<td " & InsideTD & ">" & TempStr & "</td>"

Print #1, TempStr
MyCol = MyCol + 1
Loop    ' MyCol

Print #1, "</tr>"
Next MyRow

Print #1, "</table>"

Range(HL_Locn).Value = "[Goto WebPage]"
Range(HL_Locn).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=PageName

For MyCol = Len(PageName) To 1 Step -1
If Mid(PageName, MyCol, 1) = "\" Then
    PageName = Trim(Mid(PageName, MyCol + 1, 50))
    Exit For
End If
Next MyCol

Close #1
End Sub
Function ChkBorders(MR As Integer, MC As Integer) As String
Dim Temp As String, MyBcol As String, MySides(4) As Integer, Tn As Integer

If Cells(MR, MC).Borders(xlEdgeTop).LineStyle <> xlNone Then
    If Cells(MR, MC).Borders(xlEdgeTop).LineStyle <> xlContinuous Then
    MySides(1) = 2
    Else
    MySides(1) = 1
    End If
End If

If Cells(MR, MC).Borders(xlEdgeRight).LineStyle <> xlNone Then
    If Cells(MR, MC).Borders(xlEdgeRight).LineStyle <> xlContinuous Then
    MySides(2) = 2
    Else
    MySides(2) = 1
    End If
End If

If Cells(MR, MC).Borders(xlEdgeBottom).LineStyle <> xlNone Then
    If Cells(MR, MC).Borders(xlEdgeBottom).LineStyle <> xlContinuous Then
    MySides(3) = 2
    Else
    MySides(3) = 1
    End If
End If

If Cells(MR, MC).Borders(xlEdgeLeft).LineStyle <> xlNone Then
    If Cells(MR, MC).Borders(xlEdgeLeft).LineStyle <> xlContinuous Then
    MySides(4) = 2
    Else
    MySides(4) = 1
    End If
End If

' MySides 1-4: T-R-B-L where 1 is solid, 2 is dotted

Tn = MySides(1) + MySides(2) + MySides(3) + MySides(4)
If Tn > 0 Then
If Tn = 1 Then
        If MySides(1) = 1 Then Temp = " class='tdt'"
        If MySides(2) = 1 Then Temp = " class='tdr'"
        If MySides(3) = 1 Then Temp = " class='tdb'"
        If MySides(4) = 1 Then Temp = " class='tdl'"
Else
    Temp = ""
    If MySides(1) = 2 Then Temp = Temp & "border-top-style: dotted;"
    If MySides(2) = 2 Then Temp = Temp & " border-right-style: dotted;"
    If MySides(3) = 2 Then Temp = Temp & " border-bottom-style: dotted;"
    If MySides(4) = 2 Then Temp = Temp & " border-left-style: dotted;"
   
MyBcol = " border-color:"
For n = 1 To 4
    If MySides(n) = 0 Then
    MyBcol = MyBcol & " #FFFFFF"
    Else
    MyBcol = MyBcol & " #000000"
    End If
Next n

Temp = " style= '" & Temp & MyBcol & "' "

End If
End If
If Cells(MR, MC).Interior.Color <> 16777215 Then
    Temp = Temp & " bgcolor='" & GetRGB(Cells(MR, MC).Interior.Color) & "'"
End If

If Cells(MR, MC).HorizontalAlignment = xlHAlignRight Then
    Temp = Temp & " align='right'"
End If

If Cells(MR, MC).HorizontalAlignment = xlHAlignCenter Then
    Temp = Temp & " align='center'"
End If
ChkBorders = Temp
End Function

Function GetRGB(RGB As Long) As String
Dim Red As Integer, Green As Integer, Blue As Integer
    Red = RGB And 255
    Green = RGB \ 256 And 255
    Blue = RGB \ 256 ^ 2 And 255
  GetRGB = "#" & Format(Hex(Red), "00") & Format(Hex(Green), "00") & Format(Hex(Blue), "00")
End Function
Avatar billede martin_moth Mester
13. juli 2010 - 11:53 #1
hvad mener du med "først markerede celle"?
Avatar billede martin_moth Mester
13. juli 2010 - 11:54 #2
hvis det er den celle der er markeret når macroen køres, skriver du

PageName = str(activecell.value) & ".htm"
Avatar billede martin_moth Mester
13. juli 2010 - 11:57 #3
Hvis det vel at mærke er Excel vi taler om her?
Avatar billede overgreat Forsker
13. juli 2010 - 13:48 #4
Det er excel!

Man marker område... mit ønske er at det er den celle øverst til venstre i det markerede som danner navnet!
Avatar billede martin_moth Mester
13. juli 2010 - 13:56 #5
Hvis du markerer oppefra og ned, fra venstre mod højre, kan du bruge den løsning jeg skrev:

PageName = str(activecell.value) & ".htm"
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