I'd like to extend the MS Excel 2010 by adding some more "Additional Cell Actions". (accessible via cell right-click > Additional Cell Actions). Specifically, I'd like Excel to:
recognize five-to-eight digit numbers as Part Numbers with action: "Open URL to technical docs"
recognize string "OR ## #####" (# for digit) as Order Reference with actions: "Open spec file" and "Open material file" (both Excel files located at specified paths in the intranet)
Now, I have no idea how to program this. I suspect that some XML snippet is needed and probably some VB code too. VB code wouldn't be a problem - I have macros doing those functionalities done for Excel 2003 - but I have no idea where to place it.
Please give me some pointers, I've asked Google but can't get the answer, seems that "Additional Actions" is pretty common phrase :)
This can be achieved by adding a right click event handler to the workbook
In the Workbook module add this code
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim cBut As CommandBarButton
Dim v As Variant
On Error Resume Next
v = Target
' Remove any previously added menu items
Application.CommandBars("Cell").Controls("Open URL to technical docs").Delete
Application.CommandBars("Cell").Controls("Open material file").Delete
' save cell value for use by called macro
CellValue = v
' If cell matches criteria add menu item and set macro to call on click
If IsNumeric(v) Then
If v >= 10000 And v <= 99999999 Then
Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)
With cBut
.Caption = "Open URL to technical docs"
.Style = msoButtonCaption
.OnAction = "OpenRef"
End With
End If
ElseIf v Like "OR ## #####" Then
Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)
With cBut
.Caption = "Open material file"
.Style = msoButtonCaption
.OnAction = "OpenMat"
End With
End If
End Sub
In a standard module add this code
Public CellValue As Variant
' replace MsgBox code with your logic to open files
Sub OpenRef()
MsgBox "Open Reference Doc code here for " & CellValue
End Sub
Sub OpenMat()
MsgBox "Open Material File code here for " & CellValue
End Sub
Related
I had some excel VBA code, and it doesn't work in Open Office Calc.
Code in excel copy files from list from different catalog to another.
I don't know macro programming in open office. I read about diffrent declaration, but it really hard for me. What should I change for open office?
I will really grateful for any help.
Sub copyfiles()
Dim xRg As Range, xCell As Range
Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
Dim xSPathStr As Variant, xDPathStr As Variant
Dim xVal As String
On Error Resume Next
Set xRg = Application.InputBox("Wybierz pliki do skopiowania:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
xSFileDlg.Title = "Wybierz folder z którego kopiuję:"
If xSFileDlg.Show <> -1 Then Exit Sub
xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
xDFileDlg.Title = "Wybierz folder do którego kopiuję:"
If xDFileDlg.Show <> -1 Then Exit Sub
xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
For Each xCell In xRg
xVal = xCell.Value
If TypeName(xVal) = "String" And xVal <> "" Then
FileCopy xSPathStr & xVal, xDPathStr & xVal
End If
Next
End Sub
The code needs to be entirely rewritten. OpenOffice Basic is a completely different programming platform from MS Office VBA.
One good place to start learning OpenOffice Basic is http://www.pitonyak.org/oo.php.
I'm trying to create an AppleScript that creates hyperlinks on every linked image in InDesign.
This is what I have come up with so far.
tell application "Adobe InDesign CC 2017"
activate
tell active document
set grphicBoxs to all graphics of layer activeLayer
set myLinks to {}
repeat with I in grphicBoxs
set iLink to item link of i
set end of myLinks to iLink
end repeat
repeat with theLinkRef in myLinks
set theLinkName to ((name of theLinkRef) as string)
display dialog "theLinkName: " & theLinkName
set myHyperLink to "www.myURL"
set myHyperLinkName to "myURL name"
try
set hyperLinkPreSet to make hyperlink URL destination with properties `{name:myHyperLinkName, destination URL:myHyperLink}`
on error
set hyperLinkPreSet to hyperlink URL destination myHyperLinkName
end try
try
set hyperLinkObject to make hyperlink page item source with properties `{name:myHyperLinkName, source page item:rectangle theLinkName, hidden:false}`
on error
set TheHS to hyperlink page item source myHyperLinkName
end try
display dialog "hyperLinkObject:" & hyperLinkObject
make new hyperlink with properties `{destination:myHyperLink, source:hyperLinkObject, visible:false}`
end repeat
end tell
end tell
The expected result is that the hyperlink preset that is created is applied to the chosen object. But I get this error message.
Invalid value for parameter 'source' of method 'make'. Expected page
item, but received nothing.
Is there anyone here who has successfully created hyperlinks on linked objects who can help me?
Problem solved
set activeLayer to "Layer 1"
set counter to 1
tell application "Adobe InDesign CC 2017"
activate
tell active document
set grphicBoxs to all graphics of layer activeLayer
set myLinks to {}
repeat with i in grphicBoxs
set iLink to item link of i
set end of myLinks to iLink
end repeat
repeat with theLinkRef in myLinks
set theLinkName to ((name of theLinkRef) as string)
set theLinkNameNoext to text 1 thru ((offset of "." in theLinkName) - 1) of theLinkName
set myHyperLink to "http://macscripter.net"
set myHyperLinkName to theLinkNameNoext & " " & counter
make hyperlink with properties {name:myHyperLinkName, source:make hyperlink page item source with properties {source page item:rectangle counter}, destination:make hyperlink URL destination with properties {destination URL:myHyperLink}}
set counter to counter + 1
end repeat
end tell
end tell
It seems not as easy as i thought it should be.
My Script fetches Link URL's from websites
As of now, the resulting URL's are just text and i need them to be put out as URL's (clipboard or variable) to paste them into an email message
I have tried various things from saving first to a rtf file and reading/pasting it to my email message body or copy and paste trough the clipboard.
Any help would be awesome as i can't get this solved since 2 days. Thanks
--prompt for keyword
display dialog "Keyword or Sentence" default answer "mad dog" buttons {"Done"} default button 1
set Keyword to text returned of the result
--create URL filter from Keyword
set my text item delimiters to " "
delay 0.2
set split_list to every text item of Keyword -- split in to list of everything between the spaces
set my text item delimiters to "-"
set Filter to (split_list as text) -- join, using the - as the delimter
--Open Pages
set site_url to "https://teespring.com/search?q=" & Keyword
tell application "Safari"
activate
open location site_url
end tell
-- wait until page loaded
property testingString : "Help" --Text on website to look for
set pageLoaded to false
tell application "Safari"
repeat while pageLoaded is false
set readyState to (do JavaScript "document.readyState" in document 1)
set pageText to text of document 1
if (readyState is "complete") and (pageText contains testingString) then set pageLoaded to true
delay 0.2
end repeat
end tell
-- get number of links
set theLinks to {}
tell application "Safari" to set num_links to (do JavaScript "document.links.length" in document 1)
set linkCounter to num_links - 1
-- retrieve the links
repeat with i from 0 to linkCounter
tell application "Safari" to set end of theLinks to do JavaScript "document.links[" & i & "].href" in document 1
end repeat
theLinks
set nonExcludedURLs to {}
--Filter URLs
repeat with i from 1 to length of theLinks
if item i of theLinks contains Filter then
set end of nonExcludedURLs to item i of theLinks
end if
end repeat
nonExcludedURLs
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
set nonExcludedURLs to {}
return true
else if i is the timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded
Found the solution. Maybe i described the problem not very well.
I just needed to split the resulting url's from a block of text to single lines with the following code:
set Single_URLs to ""
repeat with this_line in nonExcludedURLs -- the URL's as block of text
set Single_URLs to Single_URLs & this_line & return --split into lines
end repeat
After I did a query in openoffice-base over a customized form I want to transfer a selected set of data into a template openoffice-calc table. I know I can access the data set in openoffice-calc via pressing the Data Source (F4) button but then I only get access over the query. The best solution would be after the database query over a form a button event is required to open a openoffice-calc table from the template and insert the data from the data set.
First go to Tools -> Macros -> Organize Macros -> LibreOffice Basic and add this code. Change the path of the template file.
Sub Copy_Record_To_Calc(oEvent)
Dim oForm
Dim templatePath As String
Dim oServiceManager As Object, oDesktop As Object
Dim oFileProperties As Object
Dim oDoc As Object, oSheet As Object, oCell As Object
Dim column As Integer
oForm = oEvent.Source.getModel().getParent()
If oForm.isAfterLast() Then
Print "Hey, you are after the last element."
Exit Sub
ElseIf oForm.isBeforeFirst() Then
Print "Hey, you are before the first element."
Exit Sub
End If
templatePath = "file:///C:/Users/JimStandard/Desktop/Untitled 2.ots"
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
Set oFileProperties(0) = new com.sun.star.beans.PropertyValue
oFileProperties(0).Name = "AsTemplate"
oFileProperties(0).Value = True
Set oDoc = oDesktop.loadComponentFromURL( _
templatePath, "_blank", 0, Array(oFileProperties))
oSheet = oDoc.Sheets(0)
For column = 1 to 2
oCell = oSheet.getCellByPosition(column - 1, 0)
oCell.String = oForm.getString(column)
Next column
End Sub
Then in form design mode, right-click on the button and choose Control. In the Events tab, click the three dots next to Execute action. Click Macro... and find the Copy_Record_To_Calc macro that you added.
Now turn design mode off. Go to a record and click the button. It will open the Calc template and copy the first two columns of the current record into column A and B of the spreadsheet.
See also:
Section 4.2.1 of Andrew Pitonyak's Base Macros (PDF)
ResultSet documentation
This thread gives an example of using a Calc template.
I'm just starting to pick up ASP.Net MVC and find myself writing a lot of <%= %> in the views. Intellisense does supply the closing %>, but I find that typing the introductory <%= to be burdensome (they are tough for me to type :-)).
I've dabbled around a bit with Rails and the NetBeans IDE where I was able to type:
r<tab> - which would expand to <% %>
and
re<tab> - which would expand to <%= %>
Can something similar be done in the Visual Studio 2008 IDE?
Based on a comment, I double-checked the snippets answer below and it unfortunately doesn't run in HTML view. The other way to do this is via a recorded macro:
In your web project, start recording: CTRL+SHIFT+R
Type <%= %> then return the caret to between the spaces after the "="
Stop recording: CTRL+SHIFT+R
Insert the macro via CTRL+SHIFT+P
That could be enough, but it would be better to have it across all projects, plus we'd like a better keystroke than CTRL+SHIFT+P:
Save the Macro: Tools->Macros->Save Temporary Macro, giving it a name
Bind it to a keystroke combination:
Tools->Options, and choose the Keyboard node
Search for the name you chose
Enter a key combination (e.g. ALT+A) and click OK
Now you can press the key shortcut (e.g. ALT+A) in HTML view, it will insert <%= %>, and position the caret in the tags, ready for input.
[Old Answer: doesn't work in HTML view, unfortunately.]
For a Code Snippet, create an XML snippet file (e.g. "asp.snippet") with the name, shortcut and expansion, then use Tools -> Code Snippet Manager to add the folder where your snippet is stored.
Here's the XML for snippet that (via "asp[tab][tab]"), expands "<%= [code] %>"
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>ASP Server Tags</Title>
<Author>Chris Bowen</Author>
<Shortcut>asp</Shortcut>
<Description>ASP.NET server escape characters, including equals</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>code</ID>
<Default>Code</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[<%= $code$ $selected$%>$end$]]>
</Code>
</Snippet>
</CodeSnippet>
More details are here on MSDN.
BTW, VS has a snippet to create snippets. Just open a new XML file, then right click and choose Insert Snippet -> "Snippet".
This macro function should do it:
The main code will do one of two things, if nothing is selected it will just insert the <%= %> code construct, if you have something currently selected in the editor, it will wrap that code with the construct E.G. <%= selected code here %>
Public Sub WrapMVC()
Try
DTE.UndoContext.Open("Wrap MVC")
Dim OutText As String = ""
Dim OutFormat As String = "<%={0} %>"
DTE.ActiveDocument.Selection.Text = String.Format(OutFormat, ActiveWindowSelection)
Finally
DTE.UndoContext.Close()
End Try
End Sub
Helper Routines:
Friend Function ActiveWindowSelection() As String
If DTE.ActiveWindow.ObjectKind = EnvDTE.Constants.vsWindowKindOutput Then
Return OutputWindowSelection()
End If
If DTE.ActiveWindow.ObjectKind = "{57312C73-6202-49E9-B1E1-40EA1A6DC1F6}" Then
Return HTMLEditorSelection()
End If
Return SelectionText(DTE.ActiveWindow.Selection)
End Function
Private Function HTMLEditorSelection() As String
Dim hw As EnvDTE.HTMLWindow = ActiveDocument.ActiveWindow.Object
Dim tw As TextWindow = hw.CurrentTabObject
Return SelectionText(tw.Selection)
End Function
Private Function OutputWindowSelection() As String
Dim w As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
Dim ow As OutputWindow = w.Object
Dim owp As OutputWindowPane = ow.OutputWindowPanes.Item(ow.ActivePane.Name)
Return SelectionText(owp.TextDocument.Selection)
End Function
Private Function SelectionText(ByVal sel As EnvDTE.TextSelection) As String
If sel Is Nothing Then
Return ""
End If
If sel.Text.Length <= 2 Then
SelectWord(sel)
End If
If sel.Text.Length <= 2 Then
Return ""
End If
Return sel.Text
End Function
Private Sub SelectWord(ByVal sel As EnvDTE.TextSelection)
Dim leftPos As Integer
Dim line As Integer
Dim pt As EnvDTE.EditPoint = sel.ActivePoint.CreateEditPoint()
sel.WordLeft(True, 1)
line = sel.TextRanges.Item(1).StartPoint.Line
leftPos = sel.TextRanges.Item(1).StartPoint.LineCharOffset
pt.MoveToLineAndOffset(line, leftPos)
sel.MoveToPoint(pt)
sel.WordRight(True, 1)
End Sub
I believe Code Snippets would fit the bill.
I've found it straight forward to write a macro and then bind it to a keyboard command.
I use Tools->Macros->Macro Explorer to see what's there and you can create a new module and add in a macro to inject your code. Then you bind it to a key with Tools->Customize->Keyboard...
Since it's not too different from what you're doing, here is a macro to inject a source command with the date and username - VBScript - I didn't look to hard for other alternatives.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Module1
Private Function GetUserName() As String
GetUserName = System.Environment.UserName
End Function
Sub InjectChangeComment()
ActiveDocument().Selection().Text = "// " + System.DateTime.Now.ToString("MM-dd-yy") + " " + GetUserName() + vbTab + vbTab + vbTab
End Sub
End Module
Code Snippets in the HTML view do not work. It's slated for the next version of Visual Studio. I'd look at a Macro approach for now, or see if other tools allow for snippets in the HTML editor.
One good tool which will allow you to do this is Resharper. You can create your own templates that will do what you require but also have surround with tags too. There are a whole host of features and is well worth it for the price.