I'm trying to write a code that will open some Hyperlink files by first concatenating ranges "E4:last row"(directory path) with "F4:last row" (file name). However i'm missing the concatenating step and what i have so far will open hyperlinks in one singel row in my explorer. How could I include the concatenating step and then open the links in excel instead for further editing?
Thank you!
Sub Hyperlink ()
Dim Sh As Worksheet
Dim Rng As Range
Dim Cell As Range
Set Sh = Worksheets("Tabelle1")
With Sh
Set Rng = .Range("E4:E9")
End With
For Each Cell In Rng
ThisWorkbook.FollowHyperlink Cell.Value
'<my edit steps will be included here later>
Next Cell
End Sub
Related
Goal:
Replace the display text for any hyperlinks in an Excel sheet starting with www.google.com with Google while maintaining the original hyperlink URL and cell position.
I'm bashing together what I found online, like How To Change Multiple Hyperlink Paths At Once In Excel?.
I feel I'm close with:
Sub ReplaceHyperlinks()
Dim Ws As Worksheet
Dim xHyperlink As Hyperlink
Set Ws = Application.ActiveSheet
For Each xHyperlink In Ws.Hyperlinks
xHyperlink.TextToDisplay = Replace(xHyperlink.TextToDisplay, "www.google.com/*", "Google")
Next
End Sub
Use mid and find like
=MID(A1,5,FIND(".",A1,5)-5)
Edit:
So use hyperlink like
=HYPERLINK(B1,PROPER(B1))
Try this:
Sub ReplaceHyperlinks()
Dim Ws As Worksheet
Dim lnk As Hyperlink
Set Ws = Application.ActiveSheet
For Each lnk In Ws.Hyperlinks
If LCase(lnk.Address) Like "*google.com*" Then 'Google link ?
lnk.TextToDisplay = "Google"
End If
Next
End Sub
I was able to make a somewhat pseudo api for whatsapp using the excel formulas, but to fully automate the process i need a macro that acess the hyperlinks i generate in a cascade like event.
Like i have each link in a cell:
Link1
link2
link3
link4
I need a macro that start opening; link 1, after 5-10seconds it opens link 2 then after 5-10sec it opens link 3 and there after...
Sub Test()
Dim Sh As Worksheet
Dim Rng As Range
Dim Cell As Range
Set Sh = Worksheets("Master")
With Sh
Set Rng = .Range("G1:G" & .Cells(.Rows.Count, "G").End(xlUp).Row)
End With
For Each Cell In Rng
ThisWorkbook.FollowHyperlink Cell.Value
Next Cell
End Sub
this one nearly solved my issue ThisWorkbook.FollowHyperlink Cell.Value but i cant get this part pass tru the debuger and im not being able to issue a timer to the sintax
Is it possible to link selected range (copy with links?) to addin worksheet, then create a named range in that addin workbook and then finally create a named range, which refers to that named range stored in addin?
For example, I have this data:
I am trying to copy it with links to the addin worksheet. Addin is called "addin_test.xlam" and the worksheet stored in it is called "ws_test". I have this piece of code:
Dim rng As Range
Set rng = Selection
rng.Copy
ThisWorkbook.Sheets("ws_test").Range("A1").PasteSpecial
(How to copy links, instead of absolute values? I would like my addin sheet update its data according to activesheet values)
Then I create a named range in my addin workbook:
ThisWorkbook.Names.Add Name:="Test_addin_name", RefersTo:=ThisWorkbook.Sheets("ws_test").Range("A1:A3")
Lastly, I am looking for a way to create a named range in activesheet (open workbook) and link it to the named range in my add-in. This is what I have so far:
ActiveSheet.Names.Add Name:="Test_sheet_name", RefersTo:=ThisWorkbook.Name & "!" & ThisWorkbook.Names("Test_addin_name").Name
Named range is created correctly but sadly it returns "string" value of what I typed after RefersTo parameter. Value of this named range is not {100,200,300} but "WorkbookName...". I have tried different things but nothing seems to be working.
Can somebody help me?
Change, please changing
RefersTo:=ThisWorkbook.Name & "!" & ThisWorkbook.Names("Test_addin_name").Name
with
"[" & ThisWorkbook.Name & "]ws_test!" & ThisWorkbook.Names("Test_addin_name").RefersTo
Related to linking solution, please try the next code. It writes a formula in the range you want being updated when the add-in Name is changed:
Sub LinkAddinName()
Dim sh As Worksheet
Set sh = ActiveSheet
sh.Range("A1").Formula = "=COUNTA('" & ThisWorkbook.Name & "'!Test_addin_name)"
End Sub
Instead of CountA you can use any formula using the range. If you need to have a similar range, you must write formulas for each cell to be linked to the correspondent cell of the named range:
Sub LinkAddinNameEachCell()
Dim sh As Worksheet, cel As Range
Set sh = ActiveSheet
For Each cel In ThisWorkbook.Names("Test_addin_name").RefersToRange
sh.Range(cel.address).Formula = "='[" & ThisWorkbook.Name & "]ws_test'!" & cel.address
Next
End Sub
i want to copy the the first 7 characters of my excel file name into a column in my summary sheet. my file name typically goes something like "PR_0001_nil_officer.xls". i want to copy the "PR_0001" and paste it in column range G2:G6 of my worksheet. Also Im very new to VBA so which makes this seemingly simple task more complex to me lol
Use ThisWorkbook.Name to get the workbook name.
Use the Left function to get the left 7 characters of that name
Write it to the range in your desired worksheet
ThisWorkbook.Worksheet("Summary").Range("G2:G6").Value = Left$(ThisWorkbook.Name, 7)
Option Explicit
Sub Test()
Dim strName As String
Dim wsSummary As Worksheet
With ThisWorkbook
Set wsSummary = .Worksheets("Summary")
strName = Left(.Name, 7)
wsSummary.Range("G2:G6").Value = strName
End With
End Sub
I need to save the contents of a cell to an xml file named by another cell.
I need to perform this check for every row in the sheet.
Sub FormatRange()
Dim rng As Range
Dim row As Range
Dim cell As Range
Set rng = Range("A1:AG686")
For Each row In rng.Rows
Next row
End Sub
For each row I need to save cell AG to xml file named after cell C in the same row.
I am guessing I can use StreamWriter to write the file. I think the real problem is referencing the cells I need.
Sub FormatRange()
Dim rng As Range
Dim row As Range
Dim cell As Range
Set rng = Range("A2:AG686")
' Declare a FileSystemObject.
Dim fso As FileSystemObject
' Create a FileSystemObject.
Set fso = New FileSystemObject
' Declare a TextStream.
Dim stream As TextStream
' Create a TextStream.
For Each row In rng.Rows
Dim path As String
path = "C:\vba\" & row.Cells(1, 4) & ".xml"
' MsgBox (path + row.Cells(1, 33))
Set stream = fso.CreateTextFile(path, True)
stream.Write row.Cells(1, 33)
Next row
stream.Close
End Sub
Did it! Clustered my way through. Thanks for the suggestions.
Do you have to use VBA? I'm guessing if you know what a StreamWriter is you use C# or another .NET language. If so have a look at EPPlus, you can easily loop through your Excel sheet and use the .NET Framework.
http://epplus.codeplex.com/
Here is my flexible solution with right-click action and file choosing dialog:
Public Sub CellSaver()
Dim cell
For Each cell In Application.Selection.Cells
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Please select the file to save cell contents"
If .Show Then
With CreateObject("Scripting.FileSystemObject").CreateTextFile(.SelectedItems(1), True)
.Write cell
.Close
End With
End If
End With
Next cell
End Sub
Private Sub Workbook_Open()
With Application.CommandBars("Cell").Controls.Add(Temporary:=True)
.Caption = "Save to file"
.Style = msoButtonCaption
.OnAction = "'CellSaver'"
End With
End Sub
Credits go to:
#JMG's answer here
https://www.extendoffice.com/documents/excel/4375-excel-add-button-macro-to-right-click-menu.html
Can I simultaneously declare and assign a variable in VBA?
Excel VBA Cannot call function with onaction