I have a problem with some excel files. I'have stored three excel files in the azure cloud storage. I've implemented a download option from my website. I'am opening the file via Gembox on the server to insert one link per row with the help of the hyperlink option of Gembox.
When opening the Excel-File for the first time, instead of showing the text of the hyperlink, excel shows the error value '#NAME?'. However, there is also an security warning, so it opens in an protected view.
#NAME? error
When I click the button to edit the worksheet, the text shows appropriate.
Texts shows approriate
Any ideas on how the text can be shown appropriate from the start?
Is that a HYPERLINK formula? That would explain this behavior.
To avoid this try using the ExcelCell.Hyperlink property. You can find an example of its usage on this Hyperlink example.
var workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("Hyperlinks");
var hyperlinkStyle = workbook.Styles[BuiltInCellStyleName.Hyperlink];
var cell = worksheet.Cells["B1"];
cell.Value = "Link to GemBox homepage";
cell.Style = hyperlinkStyle;
cell.Hyperlink.Location = "https://www.gemboxsoftware.com";
cell.Hyperlink.IsExternal = true;
Or you can continue to use the HYPERLINK formula and to resolve this you would need to execute the ExcelFile.Calculate method before saving the ExcelFile.
Note, the latest version of GemBox.Spreadsheet has support for recalculating HYPERLINK function.
Related
I used the From Web function in EXCEL to load a a JSON document from the Web.
If I then Show Query, EXCEL has generated this call:
Json.Document(Web.Contents("http://blah.com/stuff"))
I'd like to edit that so rather than hard coding "http://blah.com/stuff" I'd like to pull the address from a cell in a WorkSheet.
Can anyone help me with what to put here?
Json.Document(Web.Contents(<<>>))
Give the spreadsheet cell with your URL a Name (using Name Manager) eg MyUrl
Insert a line above your Json.Document call (don't forget the comma at the end)
JsonURL = Excel.CurrentWorkbook(){[Name="MyUrl"]}[Content]{0}[Column1],
Then amend the next line to:
Json.Document(Web.Contents(JsonURL))
I am trying to do a GET request when I change a value in a cell.
The link here:
https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=(PARAMETER SHOULD BE HERE)&hoursBeforeNow=1
So what's in this cell, should change this query.
Is this possible, and if so, does anyone have a good solution for this?
Been trying to google all night but can't seem to find anyone that has done the same thing.
Adapting from this answer, this is a two-step process.
Firstly, create a named range for the cell that stores the value you will pass to the query. Details on how to do so are here. I used "StationName" as the name of the range but you can use any name you like.
Secondly, we need to incorporate the named range into the source for the query. To do so:
select any cell in the data table from the current query
click on the Query tab in the ribbon
click on Edit
look for the Query Settings panel at the right of the screen - if it's not there, go to View then click on Query Settings
the first entry in the Query Settings panel should be Source - click on that entry to select it
make sure that the formula bar is displayed by going to View then checking Formula Bar
the entry in the formula bar is too long to display so click on the V symbol at the end of the formula bar to expand it
edit the formula bar text to the text shown below - make sure to change the name of the Excel range shown at Name="StationName" to whichever name you have used
= Xml.Tables(Web.Contents("https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=" & Excel.CurrentWorkbook(){[Name="StationName"]}[Content]{0}[Column1] & "&hoursBeforeNow=1"))
This picture shows how things should now look:
Now go to Home and click on Close & Load.
You may get a warning about privacy settings - to fix this, I chose to give both the Excel file and the aviationweather.gov site the "public" level of privacy.
You can access the privacy settings by selecting a cell in the data table, going to Query and choosing Edit, going to Home and choosing Data Source Settings, selecting Global Permissions and then using Edit Permissions on the relevant entries.
To make the query automatically refresh when the cell value changes, we need to use some VBA. We will need to know which sheet the cell is on, the name of the named range which refers to that cell and the name of the query we want to refresh. The first two should be straightforward and the name of the query is just "Query - " followed by the name shown in the Queries & Connections panel.
Open up the VBA Editor with ALT-F11, double-click on the relevant sheet object in the Project Explorer to open up the related code module and paste in the following code (but change the name of the named range and the name of the query to match your names):
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, ThisWorkbook.Names("StationName").RefersToRange) _
Is Nothing And Target.Cells.Count = 1 Then
Application.EnableEvents = False
ThisWorkbook.Connections("Query - Get station from aviationweather dot gov").Refresh
Application.EnableEvents = True
End If
End Sub
Now changing the cell value should cause the query to refresh automatically
Here's some simple code to list the name of every connection in the workbook. In the VBA editor, use Insert > Module to create a new module and then paste in the following code:
Option Explicit
Sub listConnections()
Dim c As WorkbookConnection
For Each c In ThisWorkbook.Connections
MsgBox c.Name
Next c
End Sub
Each connection name will pop up in a message box like this:
and you can just copy the name you need when it pops up. You can copy the message box contents just by hitting CTRL-C but you'll need to edit out some extra stuff when you paste. Copying the message box shown above results in the following text being placed on the clipboard:
---------------------------
Microsoft Excel
---------------------------
Query - Get station from aviationweather dot gov
---------------------------
OK
---------------------------
I get daily Exchange Rate data from cbr.ru in this fashion.
screenshot of the Connection
http://www.cbr.ru/eng/currency_base/daily/?UniDbQuery.Posted=True&UniDbQuery.To=["Ticker"]
Where i use the date as a variable from an excel cell, in such a way that it refreshes automatically once the cell value changes.
(named the parameter as Ticker)
screenshot of the Parameters
Hope this uber simple method helps.
I have a Word document with VBA code to embed multiple excel sheets using the following process i.e. addOLEObject
Set IllSheet = _
ActiveDocument.Bookmarks("example1").Range.InlineShapes.AddOLEObject(ClassType:="Excel.Sheet.12", filename:=filename1, LinkToFile:=False)
however on occasion the embedded spreadsheet does not display at the top of the sheet but seemingly randomly scrolled part way down the sheet. I have checked and the excel sheet is saved with it scrolled to the top.
How can I ensure the sheet embedded is always scrolled to the top?
I can access the embedded sheet and input values as per below but can not seem to find a suitable line of code to ensure that the sheet displays at the top of active sheet.
Set objOLE = ActiveDocument.InlineShapes(3).OLEFormat
objOLE.Activate
objOLE.Object.ActiveSheet.Cells(1, 3).Value = Format(Funds, "#,###0")
Selection.MoveRight
objOLE.Object.Application.Quit
DoEvents
I have tried scroll functions etc and also want to avoid using SendKeys because it is so unreliable.
Any help greatly appreciated.
M
Does anyone know how to display the Last Saved Date of an Excel Spreadsheet on one of the worksheets?
I have found ways to do it using macros, but the spreadsheet is populated by an add-in called Jet Essentials, and this does not like macros so a solution here must not use one.
thought I would update on this.
Found out that adding to the VB Module behind the spreadsheet does not actually register as a Macro.
So here is the solution:
Press ALT + F11
Click Insert > Module
Paste the following into the window:
Code
Function LastSavedTimeStamp() As Date
LastSavedTimeStamp = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function
Save the module, close the editor and return to the worksheet.
Click in the Cell where the date is to be displayed and enter the following formula:
Code
=LastSavedTimeStamp()
This might be an alternative solution. Paste the following code into the new module:
Public Function ModDate()
ModDate =
Format(FileDateTime(ThisWorkbook.FullName), "m/d/yy h:n ampm")
End Function
Before saving your module, make sure to save your Excel file as Excel Macro-Enabled Workbook.
Paste the following code into the cell where you want to display the last modification time:
=ModDate()
I'd also like to recommend an alternative to Excel allowing you to add creation and last modification time easily. Feel free to check on RowShare and this article I wrote: https://www.rowshare.com/blog/en/2018/01/10/Displaying-Last-Modification-Time-in-Excel
May be this time stamp fit you better
Code
Function LastInputTimeStamp() As Date
LastInputTimeStamp = Now()
End Function
and each time you input data in defined cell (in my example below it is cell C36) you'll get a new constant time stamp.
As an example in Excel file may use this
=IF(C36>0,LastInputTimeStamp(),"")
You can also simple add the following into the Header or Footer of the Worksheet
Last Saved: &[Date] &[Time]
There is no built in function with this capability. The close would be to save the file in a folder named for the current date and use the =INFO("directory") function.
I've got an Access 2007 database on which I have created around 15 SQL queries to process specific data, I have created a main frame navigation menu using menus in Access, I now need to extract all th queries to Excel using VBA code, I have managed to do this with the code below by creating a button and specifying this code to it.
Private Sub query1_Click()
DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Total Users and Sessions", _
"C:\UsersandSessions.xls", , "Total Users & Sessions"
End Sub
Now my problem at the moment is that fine the query is exported to Excel, but it is done so without any formatting applied at all, I would like to add some formatting at least to the headers and maybe a title inside the spreadsheet, and one thing I dont really like is that all records are being started from the first cell. Also I would prefer that if I hit that button again in Access and the Excel spreadsheet has already exists with that query output then when clicked again it will write again to a the next available sheet.
Any suggestions or ideas a very welcome.
The short story, is you can't. You might be able to do some scripting on the Excel side to format the resulting file. If you want something pretty, you probably want to create a report.
You could, instead mount the excel sheet as a table, and then on a separated sheet in the excel file, reference the first sheet, and format the second sheet for viewing.
if you use DoCmd.TransferSpreadsheet and create an original and then edit it so that the formatting is correct, you can then run DoCmd.TransferSpreadsheet again and it will update the file with the values but keep the formatting.
However, if a human then changes the file by adding new tabs, or adding calculations, etc, then the DoCmd.TransferSpreadsheet will no longer work and will fail with an ugly error message. So what we do in our enviroment is DoCmd.TransferSpreadsheet to an original file with formatting, and follow that up in the VBA by copying the file to the users desktop, and then opening that copy so the user doesn't mess up the original source excel file.
This approach is a minimum code, clean, and easy to maintain solution. But it does require a extra "source" or original file to be hanging around. Works in Access 2007.
You also would like the results to end up on a new tab. Unfortunately, I think it will take some excel automation to do that. The VBA inside Acccess can call a function inside the VBA in Excel. That VBA could then copy the tabs as needed.
My idea would be a hybrid of Excel automation from Access and creating a template in Excel as well that would have a data table linked to your query.
To start create your data table in Excel. You can start three rows down and two columns to the right if you want or wherever. Go to your data tab and click access, find your db, choose your query you want to link to, choose table as the radio button but click properties next instead of ok, uncheck the enable background refresh, this part is critical ... under the definition tab in the connection string you will see a part that says Mode=Share Deny Write change that to Mode=Read, this will make sure that the query refreshes without errors from an MS Access VBA while the db is open and will keep your users from writing back to the db in case your query is a writeable query. Once you set that up you can adjust the table formatting however you choose from the table design tab and it will keep that formatting.
For the purposes of this we are going to assume you started the table in cell B4 ,and your named the worksheet CurrentDay, for purpose of the following VBA example be sure to replace that reference with your actual placement.
Next go back to Access and write your VBA first ensure that in your VBA window you have the reference to Microsoft Excel 12.0 Object Library is selected by going to Tools > References and selecting it from the alphabetical listing.
Create your sub as follows:
Sub query1_click()
Dim xl as Excel.Application
Dim wbk as Excel.Workbook
Dim wks as Excel.Worksheet
Dim RC as Integer
Dim CC as Integer
Set xl = New Excel.Application
Set wbk = xl.wbk.Open "X:\Filelocation\FileName.xlsx" 'name and path you saved the file you previously created
xl.Visible = True
'The above is not necessary but you may want to see your process work the first few times and it will be easier than going to task manager to end Excel if something fails.
RC = xl.Application.CountA(xl.wbk.Worksheets("CurrentDay").Range("B:B")) + 3 'This will count the rows of data in your table including your header so you can copy the data to another tab dynamically as the size of your table expands and shrinks we add 3 to it because we started at row 4 and we need the location of the last row of the record set.
CC = xl.Application.CountA(xl.wbk.Worksheets("CurrentDay").Range("4:4")) + 1 'This counts the header row and adds one space because we will use this as a location holder for our copy / paste function
Set wks = xl.wbk.Worksheets.Add
wks.Name = format(date(),"MM_dd_yy") 'this will name the tab with today's date... you can eliminate this step if you just want the sheets to be the generic Sheet1, Sheet2, etc.
With xl.wbk
.Worksheets("CurrentDay").Range(Cells(4,2),Cells(RC,CC)).Copy
.wks.PasteSpecial xlPasteValues 'This pastes the values so that the table links do not paste otherwise every tab would just refresh everyday.
.wks.PasteSpecial xlPasteFormats 'This gets your formatting.
.RefreshAll 'This will refresh your table
Wend
With xl
.Save
.Close False
.Quit
Wend
Set xl = Nothing
Set wbk = Nothing
Set wks = Nothing
End Sub
That should get you to have your data to not start on A1 of your sheets, save your old data each time, and automate the steps from access.